This is my code to get product details from database..
$i=0;
foreach($res->result() as $row ){
$products=json_decode($row->product_name,1);
//var_dump($products);
/*$sess_products[$i]['product_id'] = $row->product_id;
$sess_products[$i]['product_name'] = $row->product_name;
$sess_products[$i]['quantity'] = $row->quantity;
$sess_products[$i]['unit'] = $row->unit;
$sess_products[$i]['unit_rate'] = $row->unit_rate;
$this->session->set_userdata('sess_products',$sess_products);*/
//$post_array['cart']=$this->session->userdata('sess_products');
echo "<tr>";
echo "<td><input type='hidden' style='width:80%;' value='".$products[$i]['product_id']."' name='product_id[]'/></td>";
echo "<td><input type='hidden' style='width:80%;' value='".$products[$i]['product_name']."' name='product_name[]'/></td>";
echo "</tr>";
echo "<tr>";
echo "<td style='width:40%;'>".$products[$i]['product_name']."</td>";
echo "<td><input type='text' class='quantity' style='width:100%;' value='".$products[$i]['quantity']."' name='quantity[]'/></td>";
echo "<td><input type='text' class='quantity' style='width:100%;' value='".$products[$i]['unit']."' name='unit[]'/></td>";
echo "<td><input type='text' class='quantity' style='width:100%;' value='".$products[$i]['unit_rate']."' name='unit_rate[]'/></td>";
echo "<td><a href='javascript:void(0)' rownum='".$i."' class='remove_from_update_cart'><img src='images/close.png'/></a></td>";
echo "</tr>";
$i++;
}
Now I am able to display first item in json string by decoding it. but I want to display whole records in foreach loop.? So what will be the error??
Above code display only first record from that array.
$products=json_decode($product);inside theforeachloop? Did you try it outside the loop?$res->result_array();Documentation here$rowrepresent a JSON or$row->product_name?$row->product_namelooks more like a string column of name, not the whole product details.$product.