CodeIgniter Forums

Full Version: someone please help me bout session update,....!!!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]bang_dayat[/eluser]
i wanna make my shopping cart can be updated by increase or decrease count in it then the surfer just click "update" button...for all of that I've been make a view like this :

Code:
echo "<td colspan='2'>&lt;input type='button' name='update' value='update'
           &gt;&lt;/td>\n";

then some model like this :

Code:
function updateCartAjax($idlist){
        $cart=$_SESSION['cart'];
        $records=explode(',',$idlist);
        $updated=0;
        $totalprice=$_SESSION['totalprice'];
        if(count($records)){
            foreach($records as $record){
                if(strlen($record)){
                    $fields=explode(":",$record);
                    $id=$fields[0];
                    $ct=$fields[1];
                    if($ct > 0 && $ct!=$cart[$id]['count']){
                        $cart[$id]['count']=$ct;
                        $updated++;
                    }
                    elseif($ct==0){
                        unset($cart[$id]);
                        $updated++;
                    }
                }
            }
            if($updated){
                $totalprice=0;
                foreach($cart as $id => $product){
                    $totalprice += $product['price']*$product['count'];
                }
                $_SESSION['totalprice']=$totalprice;
                $_SESSION['cart']=$cart;
                echo $updated."records updated!";
            }
            else{
                echo "no changes detected!";
            }
        }
        else{
            echo "no records Updated!";
        }
    }

then I load it in Controller like this :

Code:
function ajax_cart(){
        $this->load->model('MOrders','',TRUE);
        return $this->MOrders->updateCartAjax($this->input->post('ids'));
    }

but when I Add the Count of product in my shopping cart, then I click the Updated Button,,..The Count is the same like before,,,I think the session not going increasly,..please someone help me,..

note:I learn bout this from Profesional CI by:Thomas Myer,...
Anyone can show me how to use cart Libraries in CI 1.7.2??
Thanx All..