ryankentp Posted June 23, 2009 Share Posted June 23, 2009 Hello, I am making a shopping cart that automatically decides what box to ship products ordered on my website in. The code connects to a mysql database and saves all the data, but I cannot find out how to echo the data, after it has been saved. I know this is the problematic code: <?php echo $store->boxes->1->cost; echo $store->boxes->2->cost; ?> I believe it doesn't work because of the numbers (1 and 2). If you know what I can do to fix it without even needing to look at my code, please respond. If not, reading more may help you. The source of the file is located at http://www.ryanpendleton.net/store.php The output of the file is located at http://www.ryanpendleton.net/output.php (I would have posted the code here, but I thought there was a little to much...) After looking at the output, it could tell it was returning the right thing, but I can not find out how to echo the price or size of the boxes. If you need me to clarify anything, don't hesitate to ask. Thanks in Advance, Ryan Pendleton Quote Link to comment https://forums.phpfreaks.com/topic/163313-problems-with-echoing-store-boxes-1-cost/ Share on other sites More sharing options...
Ken2k7 Posted June 23, 2009 Share Posted June 23, 2009 Why would you store stuff like that? Better if you don't answer that. Give this a try - echo $store->boxes->quantity->1->cost; Quote Link to comment https://forums.phpfreaks.com/topic/163313-problems-with-echoing-store-boxes-1-cost/#findComment-861672 Share on other sites More sharing options...
ryankentp Posted June 23, 2009 Author Share Posted June 23, 2009 Nope. That didn't work: Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `'{'' or `'$'' The box information isn't inside quantity. EDIT: Sorry, I mean isn't inside Quote Link to comment https://forums.phpfreaks.com/topic/163313-problems-with-echoing-store-boxes-1-cost/#findComment-861673 Share on other sites More sharing options...
ryankentp Posted December 6, 2009 Author Share Posted December 6, 2009 The solution was the put the number in curly braces like below: <?php echo $store->boxes->{1}->cost; echo $store->boxes->{2}->cost; ?> Quote Link to comment https://forums.phpfreaks.com/topic/163313-problems-with-echoing-store-boxes-1-cost/#findComment-972416 Share on other sites More sharing options...
Daniel0 Posted December 6, 2009 Share Posted December 6, 2009 It's because identifiers aren't allowed to start with digits. They must match the pattern ^[a-zA-Z_][a-zA-Z0-9_]*$ if you know regex. Otherwise you must use weird syntax to access them. Quote Link to comment https://forums.phpfreaks.com/topic/163313-problems-with-echoing-store-boxes-1-cost/#findComment-972426 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.