简体   繁体   中英

Session is saving only records and it's not saving the rest of the records in PHP?

function  mycart($mydate=null,$day=null)
 {
  $mycart= $this->session->userdata('mycart');
  $totalprice=$this->session->userdata('totalprice');

    if($this->limitation($mydate) && (!(isset($mycart[$mydate]))) )
    {          
     $mycart[$mydate] = array(
     'meal' =>$this->session->userdata('meal'),
     'day' =>$day,
     'date' =>$mydate,
     'disable'=>FALSE,
     'flag'=>null);
     $this->session->set_userdata('mycart',$mycart);  

     $this->session->set_userdata('totalprice',$totalprice);
    }// end  of if        

 }//  end  of  function

I am saving an array called $mycart in session but only 10 carts, ie, only 10 records are getting saved after which 11th one is not getting saved in session. The session only save 10 array element can any one tell me why??

The code you've posted is irrelevant to the problem you describe.

Try creating code from scratch to replicate the issue.

C.

Perhaps your issue is with your array itself. If you have two carts with the same $mydate value, the latter will override the first value. You need to use a multidimensional array in this case, ie:

$mycart[$mydate][] = array(
     'meal' =>$this->session->userdata('meal'),
     'day' =>$day,
     'date' =>$mydate,
     'disable'=>FALSE,
     'flag'=>null);

Otherwise you may perhaps be skipping with your first check on isset($mycart[$mydate]) , which would essentially skip over an entire cart.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM