Jump to content

multi-dimensional array - what am I doing wrong?


caughtinweb

Recommended Posts

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]

<?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...

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.