palash140
palash140

Reputation: 733

codeigniter where with result not working

$this->select("unm")->from("user")->where(array("age"=>20))->result();

not working, even any query including where.

Not able to use, result(), row() etc.

$rowSet=$this->select("unm")->from("user")->where(array("age"=>20));
$rowSet->result();

also not working

Fatal error: Call to undefined method CI_DB_mysql_driver::result() in C:\xampp\htdocs\ci\application\models\testModel.php on line 24

Upvotes: 0

Views: 712

Answers (3)

Hacker Rocker
Hacker Rocker

Reputation: 251

Try this:

$where_array = array("age"=>20);

$result = $this->db->select('unm')
         ->from()
         ->where($where_array)
         ->get()->result();

print_r($result); gives you output in the following form

array([0]=>stdobj(),[1]=>stdobj().....)

Upvotes: 0

Bira
Bira

Reputation: 5506

Why don't you use a function like this?

public function getDataByID($id) {
    $this->db->select ( '*' );
    $this->db->from ( 'item' );
    $this->db->where ( 'id', $id );

    $query = $this->db->get ();
    $row = $query->first_row ();
    return $row;
}

Upvotes: 0

Jenz
Jenz

Reputation: 8369

You didn't executed the query. Try with

$rowSet=$this->select("unm")
->from("user")
->where(array("age"=>20));
$rowSet = $this->db->get();   // this was missing
$query->result();

For Reference

Upvotes: 2

Related Questions