justinh Posted January 22, 2009 Share Posted January 22, 2009 http://www.wmptest.com/hrfinal/additem.html <?php session_start(); if(isset($_GET['clearlist'])){ session_destroy(); }else{ $item_to_add = $_GET['item']; $count = count($_SESSION['items']); if ( ! isset ( $_SESSION['items'] ) ) { echo "no items set... adding item"; $_SESSION['items'] = array ( $_GET['item'], 1); } else { if ( ! in_array ( $_GET['item'], $_SESSION['items'] ) ) { echo "there is items, but this item doesn't exist"; $_SESSION['items'][] = $_GET['item']; $_SESSION['items'][$_GET['item']][] = 1; } else { echo "there is items, and this item exist, so adding to qty"; $_SESSION['items']['$item_to_add'][] = $_SESSION['items']['$item_to_add'][1] + 1; } } if ( isset ( $_SESSION['items'] ) ) { } else { echo "No Items exist!"; } } ?> Okay, I know everything is finally working.. I just need to know how I would go about displaying the items. If anyone has an idea of what I should be looking into please post. Thanks, Justin Quote Link to comment https://forums.phpfreaks.com/topic/141985-how-would-i-go-about-displaying-this/ Share on other sites More sharing options...
justinh Posted January 22, 2009 Author Share Posted January 22, 2009 I tried this <?php session_start(); if(isset($_GET['clearlist'])){ session_destroy(); }else{ $item_to_add = $_GET['item']; $count = count($_SESSION['items']); if ( ! isset ( $_SESSION['items'] ) ) { echo "no items set... adding item"; $_SESSION['items'] = array ( $_GET['item'], 1); } else { if ( ! in_array ( $_GET['item'], $_SESSION['items'] ) ) { echo "there is items, but this item doesn't exist"; $_SESSION['items'][] = $_GET['item']; $_SESSION['items'][$_GET['item']][] = 1; } else { echo "there is items, and this item exist, so adding to qty"; $_SESSION['items']['$item_to_add'][] = $_SESSION['items']['$item_to_add'][1] + 1; } } if ( isset ( $_SESSION['items'] ) ) { foreach($_SESSION['items'] AS $key){ foreach($_SESSION['items'][1] AS qty){ echo $key . "x" . $qty ."<br />"; } } } else { echo "No Items exist!"; } } ?> But this reports an error I have never seen before.. Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM in /homepages/29/d119570661/htdocs/wmptest.com/hrfinal/inc.additem.php on line 42 Quote Link to comment https://forums.phpfreaks.com/topic/141985-how-would-i-go-about-displaying-this/#findComment-743424 Share on other sites More sharing options...
Prismatic Posted January 22, 2009 Share Posted January 22, 2009 foreach($_SESSION['items'][1] AS qty){ to foreach($_SESSION['items'][1] AS $qty){ Quote Link to comment https://forums.phpfreaks.com/topic/141985-how-would-i-go-about-displaying-this/#findComment-743434 Share on other sites More sharing options...
justinh Posted January 22, 2009 Author Share Posted January 22, 2009 Okay im trying a different way, but it doesn't work.. This is making me frustrated. <?php session_start(); if(isset($_GET['clearlist'])){ session_destroy(); }else{ $item_to_add = $_GET['item']; $count = count($_SESSION['items']); if ( ! isset ( $_SESSION['items'] ) ) { echo "no items set... adding item"; $_SESSION['items'] = array ( $_GET['item']."|1"); } else { if ( ! in_array ( $_GET['item'], $_SESSION['items'] ) ) { echo "there is items, but this item doesn't exist"; $_SESSION['items'] = $_GET['item']."|1"; } else { echo "there is items, and this item exist, so adding to qty"; $explosive = $_SESSION['items'][$item_to_add]; $pieces = explode("|", $explosive); $newqty = $pieces[1] + 1; $item = $pieces[0]; $_SESSION['items'][$item_to_add] = $item."|".$newqty; } } if ( isset ( $_SESSION['items'] ) ) { foreach($_SESSION['items'] AS $key){ $getiteminfo = explode("|", $key); $item = $getiteminfo[0]; $qty = $getiteminfo[1]; echo "<br>".$item ." x ".$qty."<br />"; } } else { echo "No Items exist!"; } } ?> to see the gaggle of errors just go here: http://www.wmptest.com/hrfinal/additem.html Quote Link to comment https://forums.phpfreaks.com/topic/141985-how-would-i-go-about-displaying-this/#findComment-743451 Share on other sites More sharing options...
sasa Posted January 22, 2009 Share Posted January 22, 2009 try <?php session_start(); if(isset($_GET['clearlist'])){ session_destroy(); }else{ $item_to_add = $_GET['item']; if ( ! isset ( $_SESSION['items'] ) ) { echo "no items set... adding item"; $_SESSION['items'][$item_to_add] = 1; } else { if ( ! isset($_SESSION['items'][$item_to_add] ) ) { echo "there is items, but this item doesn't exist"; $_SESSION['items'][$item_to_add] = 1; } else { echo "there is items, and this item exist, so adding to qty"; $_SESSION['items']['$item_to_add']++; } } if ( isset ( $_SESSION['items'] ) ) { foreach($_SESSION['items'] AS $key => $qty){ echo $key . "x" . $qty ."<br />"; } } else { echo "No Items exist!"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/141985-how-would-i-go-about-displaying-this/#findComment-743472 Share on other sites More sharing options...
justinh Posted January 22, 2009 Author Share Posted January 22, 2009 This got rid of the errors But... It isn't working. =( http://www.wmptest.com/hrfinal/additem.html Quote Link to comment https://forums.phpfreaks.com/topic/141985-how-would-i-go-about-displaying-this/#findComment-743481 Share on other sites More sharing options...
justinh Posted January 22, 2009 Author Share Posted January 22, 2009 Is this impossible to do or something? If you need more information to help me, please ask. Quote Link to comment https://forums.phpfreaks.com/topic/141985-how-would-i-go-about-displaying-this/#findComment-743508 Share on other sites More sharing options...
justinh Posted January 22, 2009 Author Share Posted January 22, 2009 Anything would be nice, ''Your a dumbass, get off the forums.." anything... Quote Link to comment https://forums.phpfreaks.com/topic/141985-how-would-i-go-about-displaying-this/#findComment-743529 Share on other sites More sharing options...
sasa Posted January 22, 2009 Share Posted January 22, 2009 ups i made mistake in line 18 in posted code change $_SESSION['items']['$item_to_add']++; to $_SESSION['items'][$item_to_add]++; Quote Link to comment https://forums.phpfreaks.com/topic/141985-how-would-i-go-about-displaying-this/#findComment-743548 Share on other sites More sharing options...
justinh Posted January 22, 2009 Author Share Posted January 22, 2009 Thank you so much. i <3 you. Quote Link to comment https://forums.phpfreaks.com/topic/141985-how-would-i-go-about-displaying-this/#findComment-743554 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.