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']-&gt;items[$i]-&gt;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

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.

Hey

I really don’t get this stuff that well.

Any chance at all of showing me the sample code?

mrmbarnes

Look at your own 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():wink:
So the first item gets put into $productcodeid[0], the second into $productcodeid[1], etc…

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?

Show us the output of


var_dump($_SESSION);

change the values slightly if they are secret.

This line is not making sense to me at all:


 $_SESSION['SHOP']->Get_Size();

and makes me believe there is a lot more code involved than you are showing us.

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.

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!

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.


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 );