Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder anarchy3200's Avatar
    Join Date
    Mar 2003
    Location
    England
    Posts
    261
    Thanks
    0
    Thanked 1 Time in 1 Post

    Shopping cart info

    Hi,

    i am making a shopping cart but got stuck on what i should use to store the values,

    e.g. name and price of multiple items

    should i store this all into a string or something else


    any help appreciated

  • #2
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    I think your best bet would be to use sessions.

  • #3
    Regular Coder anarchy3200's Avatar
    Join Date
    Mar 2003
    Location
    England
    Posts
    261
    Thanks
    0
    Thanked 1 Time in 1 Post
    sessions would be easiest but how would i set the multiple items

    at the moment i have:

    PHP Code:
    $_SESSION['name'] = 'Guitar<del>15.99' 
    to set the value (these are set from a get)

    and i have
    PHP Code:
    @list($name$price) = explode("<del>"$_SESSION['name']);

    echo 
    $name;
    echo 
    $price
    to view it but this will only handle 1 item, how would i expand this?

    Thanks for any help.

  • #4
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    Hopefully this will help...

    Use arrays to hole the quantity, itemID (sku) and what ever else. See example:

    PHP Code:
    <?php
    session_start
    ();
    $_SESSION['sku'][0]="01-003-sku";
    $_SESSION['qty'][0]=1;
    $_SESSION['sku'][1]="05-33-14da3";
    $_SESSION['qty'][1]=2;
    ?>
    <a href="page2.php">See session info</a>
    Now on the second page (page2.php) I can print them out (or modify them if I want...

    PHP Code:
    <?php
    session_start
    ();
    print 
    "<pre>";
    print_r($_SESSION);
    print 
    "</pre>";
    ?>
    Hope this helps.

  • #5
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    Or, on page 1 you can even do this...

    PHP Code:
    <?php
    session_start
    ();
    $_SESSION['items']["01-003-sku"]=1;
    $_SESSION['items']["05-33-14da3"]=3;
    ?>
    <a href="page2.php">See session info</a>

  • #6
    Regular Coder anarchy3200's Avatar
    Join Date
    Mar 2003
    Location
    England
    Posts
    261
    Thanks
    0
    Thanked 1 Time in 1 Post
    last questions for now,

    what does the <pre> bit do?

    and how would i view the information on its own without the layout around it?


    thanks for all the help.

  • #7
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why don't you immedeately write it to the db or to a persistent cookie?
    Otherwise all info is lost when the session is terminated.

    You'll need to write it to the db sooner or later so why first drag it along in a session-variable?
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #8
    Regular Coder anarchy3200's Avatar
    Join Date
    Mar 2003
    Location
    England
    Posts
    261
    Thanks
    0
    Thanked 1 Time in 1 Post
    i'm not using a db but how would i do a similar thing and write it to a cookie

    thanks for any help.

    would i just be able to swap the session for cookie and is there an easy way to just roll off all the arrays of the cookie in a list
    Last edited by anarchy3200; 05-12-2004 at 09:11 PM.

  • #9
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wait a minute.

    If you don't use a db and would store it inside a cookie or session, how do you then get the bought items? I hope you're not planning on have them mailed to you.
    You do realise that yu don't have control over the session and cookiedata? The sessiondata is just removed when the session end, and the cookie is stored on the client.

    Storing i in a cookie is as simple as

    setcookie ('selected', $array_shoppigcart, time()+31536000); // expires after 1 year

    to get the data:

    $_COOKIE['selected']

    $array_shoppigcart is then the array with your products
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #10
    Regular Coder anarchy3200's Avatar
    Join Date
    Mar 2003
    Location
    England
    Posts
    261
    Thanks
    0
    Thanked 1 Time in 1 Post
    what i am going to do is store it through the session and then it will be saved to a db properly when the customer goes to the checkout so that i am not saving data that does not come out to an order.

    sorted it now so thanks everyone for the help

    Mike


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •