SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Evangelist
    Join Date
    Nov 2003
    Location
    Brisbane, Australia
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HELP - Getting Information Out of a Session

    Hi All

    Normally I would site down and work this out but I was meant to have this website live today and I still have a bit of programming left on it.

    I would really appreciate it if someone could just tell me how to do this with sample code that will work.

    The website sells 3 products and depending on which product you buy will depend on what delivery and registration pay you will get.

    I have all the information in my shopping cart sessions. I just need to list out the 3 codes.

    I have:

    for ($i = 0; $i < $_SESSION['SHOP']->Get_Size(); $i++) {

    $productcodeid[$i] = $_SESSION['SHOP']->items[$i]->Get_ID();

    }

    and

    echo ("<p>" . $productcodeid[1] . " - " . $productcodeid[2] . " - " . $productcodeid[3] ." - $i</p>");

    No matter what I keep trying I keep getting - 9767 - - - 2 as there are 2 products in the cart right now.

    PLEASE HELP!

    mrmbarnes

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    You started your loop at 0, not 1. So if there are two items, they will be at keys 0 and 1, not 1 and 2.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Evangelist
    Join Date
    Nov 2003
    Location
    Brisbane, Australia
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey

    I really don't get this stuff that well.

    Any chance at all of showing me the sample code?

    mrmbarnes

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Look at your own code.
    Code:
    for ($i = 0; $i < $_SESSION['SHOP']->Get_Size(); $i++) {
    $productcodeid[$i] = $_SESSION['SHOP']->items[$i]->Get_ID();
    }
    $i starts at 0 ($i = 0). Increases by 1 every time it loops ($i++), and stops when it's no longer smaller than the number of items in the cart ($i < $_SESSION['SHOP']->Get_Size();)
    So the first item gets put into $productcodeid[0], the second into $productcodeid[1], etc...
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    SitePoint Evangelist
    Join Date
    Nov 2003
    Location
    Brisbane, Australia
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey

    I did try that as part of my playing around and the result I get is: 9 - 7 - 6 - 3.

    The result I need is 9767 - 9768 - 9769 - 3.

    Any ideas?

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Show us the output of
    PHP Code:
    var_dump($_SESSION); 
    change the values slightly if they are secret.

    This line is not making sense to me at all:
    PHP Code:
     $_SESSION['SHOP']->Get_Size(); 
    and makes me believe there is a lot more code involved than you are showing us.

  7. #7
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    just says to me that whatever's in $_SESSION['SHOP'] is an object with a Get_Size function defined.

    Barnes' output suggests that at some point after the end of the loop, $productcodeid gets overwritten with a singular value, or the get_ID method is returning a single integer.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  8. #8
    SitePoint Evangelist
    Join Date
    Nov 2003
    Location
    Brisbane, Australia
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    I really appreciate your help with this as I am not that great with sessions.

    Here is what is returned:

    array(7) { ["SHOP"]=> &object(ShoppingCart)#1 (14) { ["items"]=> array(3) { [0]=> object(ShelfItem)#2 (6) { ["ID_"]=> string(4) "9767" ["QUANTITY_"]=> string(1) "1" ["PRICE_"]=> string(4) "0.01" ["NAME_"]=> string(36) "SWC Hot Prospects - Download Version" ["STOCK_"]=> string(0) "" ["EXTRA_"]=> NULL } [1]=> object(ShelfItem)#3 (6) { ["ID_"]=> string(4) "9768" ["QUANTITY_"]=> string(1) "1" ["PRICE_"]=> string(3) "169" ["NAME_"]=> string(36) "SWC Hot Prospect - CD Copy Australia" ["STOCK_"]=> string(0) "" ["EXTRA_"]=> NULL } [2]=> object(ShelfItem)#4 (6) { ["ID_"]=> string(4) "9769" ["QUANTITY_"]=> string(1) "1" ["PRICE_"]=> string(3) "179" ["NAME_"]=> string(45) "SWC Hot Prospects - CD Copy Outside Australia" ["STOCK_"]=> string(0) "" ["EXTRA_"]=> NULL } } ["SITE_ID"]=> NULL ["SALE_ID"]=> int(1317686957) ["BUSINESS_NAME"]=> string(0) "" ["FIRST_NAME"]=> string(0) "" ["LAST_NAME"]=> string(0) "" ["EMAIL"]=> string(0) "" ["ADDRESS_1"]=> string(0) "" ["ADDRESS_2"]=> string(0) "" ["SUBURB"]=> string(0) "" ["STATE"]=> string(0) "" ["POSTCODE"]=> string(0) "" ["COMMENTS"]=> string(0) "" ["DELIVERY_COST"]=> int(-1) } ["auth"]=> &NULL ["ssauth"]=> &NULL ["logname"]=> &NULL ["delinfo"]=> &int(1) ["therandomid"]=> &NULL ["sentto"]=> &NULL }

    Help!

  9. #9
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    So, is GET_ID() returning the whole number or are you echoing it incorrectly?

    Just start echoing the values onto the page and check them carefully.

    PHP Code:
    for ($i 0$i $_SESSION['SHOP']->Get_Size(); $i++) {

    // check the values are extracted from the object in the SESSION
    echo $_SESSION['SHOP']->items[$i]->Get_ID();

    $productcodeid[$i] = $_SESSION['SHOP']->items[$i]->Get_ID();



    }
    // then check whether the values made it into the array
    var_dump$productcodeid ); 


Bookmarks

Posting Permissions

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