I’m using sessions to store products viewed, but I’m having a problem printing out all of the items when I query the database.
Controller
$hello_world = $this->session->all_userdata();
foreach($hello_world as $key=>$product_id) {
$query['products'] = $this->Global_products->globalFindProducts($product_id);
echo $product_id; // Right here it echos all the items in the session.
}
Model
function globalFindProducts($product_id)
{
$this->db->join('price','product.modelNumber = price.modelNumber','left')->where('product.modelNumber',$product_id);
$this->db->group_by('product.modelNumber');
$query = $this->db->get('by.product');
return $query->result();
}
View
<?php foreach($products as $product) { ?>
<div><?php echo $product->name; ?></div>
<?php } ?>
In my view I can only see one item, not all of them. Can someone please give me your advice as to how you would approach solving this problem?
Thanks in advance
Try this, I haven’t really coded in CodeIgniter, so its a best guess:
Controller
Note: Here I’m making the
$query['products']an array, so all results from$this->Global_products->globalFindProducts($product_id);are stored