Reputation: 643
I am trying to retrieve data from an sql query, in codeigniter. but when I am trying to fetch query result ,I am getting only one field. In the query I have trying to get 2 fields. When I try to print the query result using var_dump the result I am getting is
object(stdClass)#33 (1) { ["product_id"]=> string(4) "1904" }
My Query is:
$this->db->select("product_id","product_name")
->from('sale_items')
->where('sale_items.sale_id',4221);
$q1 = $this->db->get();
if ($q1->num_rows() > 0) {
foreach (($q1->result()) as $row1) {
$data1[] = $row1;
}
} else {
$data1 = NULL;
}
echo "<br>";
foreach($data1 as $prdtname)
{ echo "<br>";
echo var_dump($prdtname);
echo "<br>";
}
and the result is:
object(stdClass)#32 (1) { ["product_id"]=> string(4) "1887" }
object(stdClass)#33 (1) { ["product_id"]=> string(4) "1904" }
As you see, I am not getting the second field that is product_name
. I do not know what is the problem with my query.Can anyone help me.. Thanks in advance.
Upvotes: 0
Views: 233
Reputation: 1617
Change your select statement to :
$this->db->select("product_id ,product_name")
Upvotes: 2