1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to display total quantity of items in a shopping cart on other page on a website

Discussion in 'PHP' started by callisto11, Jul 9, 2008.

  1. #1
    Hi Everyone,

    I have a problem, I've created a shopping cart in php, this is what happens:

    -When a user presses the add button on a gallery page it adds the details of the item to the shopping cart.

    -This works perfectly fine.

    -What I really need help with is, how I can let the user see how many items they have in their shopping cart on other pages while they are still browsering the site.

    -So once they pressed the add button it will show the total quantity of cart.

    I hope this is clear enough.

    Thank you
    :confused:
     
    callisto11, Jul 9, 2008 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    I'm assuming your shopping cart runs on sessions (sensible ones normally do.)

    Surely you could just use session_start(); on a page, then read the session variables from there? The only data you really need to hold is the id number of the product in question and the quantity, and you can just multiply up from there.

    Dan
     
    Danltn, Jul 9, 2008 IP
  3. callisto11

    callisto11 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    To Danltn,

    I not sure if I understood what you saying, coz Im very new to php, it would help if u could show me an example!

    yes I am using session.

    Example of what I want to do is like on an amazon site, where when a user clicks add, it shows the user the item in the shopping basket, all I want it to do is count the total quantity and display it, even if the user goes on other pages in the site.

    Thank you
     
    callisto11, Jul 9, 2008 IP
  4. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #4
    session_start();
    print_r($_SESSION);

    Tell me what you get.
     
    Danltn, Jul 9, 2008 IP
  5. callisto11

    callisto11 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    To Danltn,
    I get :
    Array ()
    display on the page.
     
    callisto11, Jul 9, 2008 IP
  6. o_rly

    o_rly Guest

    Messages:
    35
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    make sure your session_start() is above any kind of html code or echo/print statements
     
    o_rly, Jul 9, 2008 IP
  7. Danny

    Danny Active Member

    Messages:
    732
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    78
    #7
    This is something I came up against.

    Rather than use the session objects if you want to get tricky, look at ajax, I ajaxified a shopoping cart system i wrote for a client, so all items added to the cart were done via ajax calls, I then had a widget, or box that simply queried the data from the cart, on cart pages, the ajax function that ads to the cart, also updated the widget.

    On non-cart pages, it didn't really need to have ajax, so I run a straight query in the widget that grabs the data.

    However on mine sessions were consistent across the site, and I could use that as a pointer to the data
     
    Danny, Jul 9, 2008 IP
  8. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #8
    When you build your ajax shopping cart, I'm sure you create a way to delete all junk data from your database when people start shopping and never checkout. :)
     
    php-lover, Jul 9, 2008 IP