caughtinweb Posted September 14, 2009 Share Posted September 14, 2009 I don't know where I'm going wrong on this sucker... Want just a simple list: item in first column, photo of item in second column. Photo of this code's output is attached below my post. <?php $shopping_list = $_SESSION['wantlist']; ?> <?php echo "<pre>"; print_r($shopping_list); echo "</pre>"; ?> <table width="300" border="1" cellpadding="20"> <caption> My Bead Want List </caption> <?php foreach ($shopping_list as $key_1 => $val) { foreach ($val as $key_2 => $val_2) { echo('<tr> <td class="name">'.$shopping_list[$key_1][$key_2].'</td> <td class="thumbnail"><img width="87" height="87" src='.$shopping_list[$key_1][$key_2].' /></td> </tr>') ; } } ?> I keep changing the code but can't get it to go through the array and pull out what I need, in the row and column I need it to be in. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/174144-multi-dimensional-array-what-am-i-doing-wrong/ Share on other sites More sharing options...
AviNahum Posted September 14, 2009 Share Posted September 14, 2009 <?php $shopping_list = $_SESSION['wantlist']; ?> <?php echo "<pre>"; print_r($shopping_list); echo "</pre>"; ?> <table width="300" border="1" cellpadding="20"> <caption> My Bead Want List </caption> <?php foreach ($shopping_list as $key_1 => $val) { foreach ($val as $key_2 => $val_2) { echo('<tr> <td class="name">'.$shopping_list[$key_1][$key_2].'</td> <td class="thumbnail"><img width="87" height="87" src="'.$shopping_list[$key_1][$key_2].'" /></td> </tr>') ; } } ?> i'm not sure it will work... Link to comment https://forums.phpfreaks.com/topic/174144-multi-dimensional-array-what-am-i-doing-wrong/#findComment-917976 Share on other sites More sharing options...
mikesta707 Posted September 14, 2009 Share Posted September 14, 2009 foreach ($shopping_list as $key_1 => $val) { foreach ($val as $key_2 => $val_2) { echo('<tr> <td class="name">'.$key_2.'</td> <td class="thumbnail"><img width="87" height="87" src='.$val_2.' /></td> </tr>') ; } } try that? Link to comment https://forums.phpfreaks.com/topic/174144-multi-dimensional-array-what-am-i-doing-wrong/#findComment-917978 Share on other sites More sharing options...
caughtinweb Posted September 14, 2009 Author Share Posted September 14, 2009 It works! It's so simple! Thank you. Link to comment https://forums.phpfreaks.com/topic/174144-multi-dimensional-array-what-am-i-doing-wrong/#findComment-917985 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.