Welcome Guest, Not a member yet? Register   Sign In
Issue with the Shopping Cart
#1

(This post was last modified: 03-31-2020, 03:41 PM by RuthvikR.)

Normally I can add the array data to cart by giving values in it and I can fetch the data. But I issue is I cannot add the data which are coming from database or by giving the values  from views.

Please give me the solution.

 Below are my code

View:
< a href="<?php echo site_url('product/addtocart/'.$row->id)?>">

Controller:
function addtocart(){
$id = $this->uri->segment(3);
$data['post'] = $this->model->get_product($id);
foreach($data as $item){
$name = $item->product_name;
$price = $item->price;
$image = $item->image;
}
$data = array(
'id' => $id,
'name' => $name,
'price' => $price,
'image' => $image,
'qty' => 1);
$this->cart->insert($data);
print_r($this->cart->contents());
}


I couldn't find any errors in code but why its not adding???????
Reply
#2

Your foreach loop is over writing all your variables each time through the loop.

If your only getting one row from the database you do not need a foreach loop.

Did you do a var_dump() of the $data['post'] to make sure your getting the values?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB