Announcement

Collapse
No announcement yet.

unregister one (not all) session..

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • unregister one (not all) session..

    hi, i'm working on a shopping cart. i store the necesary field in session and pass it to user cart when user add the item to cart.

    i do not know how to delete a session, for eg, if user adds 3 items in the cart and he wants to delete one of the item, how can i delete just one of the id instead of all the ids...

    this is how i store my session:
    PHP Code:
    if (isset($HTTP_POST_VARS['pid']['pid'])) 
        {
            if (
    is_array($_SESSION['pid']))
            {
                if (!
    in_array($HTTP_POST_VARS['pid']['pid'], $_SESSION['pid']))
                {
                                    
    $_SESSION['pid'][] = $HTTP_POST_VARS['pid']['pid'];
                }    
            }else
            {
                            
    $_SESSION['pid'][] = $HTTP_POST_VARS['pid']['pid'];
            }
        } 
    this is the checkbox:

    PHP Code:
    print "<td width=5%><input type=checkbox name=cb[] value=\"$i\"></td>\n"
    and this, when user check the checkbox and click delete:

    PHP Code:
    for ($i=0$i<count($cb); $i++) 
            { 
                unset( 
    $_SESSION['pid'][$cb[$i]] ); 
            } 
    if i have 2 or more records, and i click the first record to be deleted, it will delete all the records i have it there.

    pls advice!!
    Last edited by joyce; Thu 29 Aug '02, 1:03am.

  • #2
    Re: unregister one (not all) session..

    Originally posted by joyce
    PHP Code:
    for ($i=0$i<count($cb); $i++) 
            { 
                unset( 
    $_SESSION['pid'][$cb[$i]] ); 
            } 
    should be

    PHP Code:
    for ($i 0$i count($cb); $i++) {
        if (isset(
    $cb[$i])) {
            unset(
    $_SESSION['pid'][$cb[$i]]);
        }

    That checks to make sure the box is checked for each one, and if it is then it deletes it.

    Comment


    • #3
      hi, tried the code u posted, but it gave me the same result. when i click one record, it will delete all the reocrds i have instead of just one of the record.

      this is the session file(when i add 2 records into the cart):
      pid|a:2:{i:0;s:1:"4";i:1;s:1:"1";}
      and this is the session file when i choose one of the record to delete:
      pid|a:1:{i:1;s:1:"1";}
      but on my page, when choose one record to be deleted, it deletes all the records. so it shows an empty cart at my page.

      Comment

      widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
      Working...
      X