Reputation: 83
the "where" statement in my query is not working.
$this->db->select(array("pr_id","id","unit_id","item_description","quantity","unit_cost","total_cost"));
$this->db->where('id','1');
$this->db->from("tblitem");
The select and from statement is perfectly fine. My datatables is appearing. But it disregards the where statement. I dont know if my statement is right. please help me thanks.
Upvotes: 0
Views: 109
Reputation: 1270
Please remove array from select statement, such that your query looks like this:
$this->db->select(`pr_id`,`id`,`unit_id`,`item_description`,`quantity`,`unit_cost`,`total_cost`);
$this->db->where('id',1);
$this->db->from('tblitem');
$result=$this->db->get();
Then if you want to access a single row, use:
$row = $result->row();
Or if the query results in a pure array, or an empty array when no result is found, use:
$result->result_array().
Example:
foreach ($result->result_array() as $row)
{
echo $row['title'];
echo $row['name'];
echo $row['body'];
}
Upvotes: 0
Reputation: 11
Remove array For Select Query and remove quotes for id(int)
$this->db->select("pr_id,id,unit_id,item_description,quantity,unit_cost,total_cost");
$this->db->from('tblitem');
$this->db->where('id',1);
$query = $this->db->get();
return $query->result();
Upvotes: 1
Reputation: 34
Try This
$this->db->select("pr_id,id,unit_id,item_description,quantity,unit_cost,total_cost");
$this->db->get_Where('tblitem', array('id'=>'1'));
echo $this->db->result()
Hope This Help
Upvotes: 0
Reputation: 337
Remove array from select. You can just select table columns by separating them with commas.
And also replace
$this->db->where('id','1');
with
$this->db->where('id',1);
Note: Remove quotes if the id
field is int.
May be this will help.
Upvotes: 0
Reputation: 1755
I think this is correct way.
$this->db->select("pr_id","id","unit_id","item_description","quantity","unit_cost","total_cost");
$this->db->where('id',1);
$this->db->from("tblitem");
Upvotes: 0