Jump to content

help getting more than 1 item into an array with session variables


caughtinweb

Recommended Posts

I'm trying to come up with a "want list" of beads.

 

I'm dynamically generating a table, with arrays based on session variables to display the list of beads chosen by the user to add to the "want list", inventory number first, then a photo of that bead next to the inventory number.

 

The 2nd item, the photo, is my problem:  I have managed to store and correctly display a table of the 1 item, the bead inventory numbers. When I try to store the 2nd item, the path to the photo, all I get is the one most recent photo displaying next to ALL of the inventory numbers in the array. 

 

So I want this:

111A ........... photo of bead 111A

523G ........... photo of bead 523G

298B ........... photo of bead 298B

 

But what I'm getting is this:

111A ........... photo of bead 298B

523G ........... photo of bead 298B

298B ........... photo of bead 298B

 

This include file sets the session variables:

<form id="form1" name="form1" method="post" action="../includes/wantlist.php">
<input type="submit" name="wantlist" value="add to want list">
<?php //put the bead into the list
$_SESSION['beadiwant'] = $mainImage;
// $pathtothumb = '"../images/'.$downname.'/small/'.$row['prodCode'].'.jpg"'; 
$pathtothumb = '"../images/'.$downname.'/small/'.$row['prodCode'].'.jpg"';
// echo $pathtothumb;
$_SESSION['pathtothumb'] = $pathtothumb; 
echo $_SESSION['pathtothumb'];
//result is "../images/fimo/small/111A-1432D.jpg"
?>
</form>

 

Here is the include file where the array action is supposed to take place. (A lot of the code in here is my debugging attempts with echo statements etc.):

 

<?php 
	session_start();
?>

.............

<body>
<?php
echo '<p>I want...</p>';
echo $_SESSION['pathtothumb'];
// if the array $wantlist does not exist, then define it as an array and stick the 'beadiwant' into it
//$_SESSION['wantlist'][] = $_SESSION['beadiwant'];
$_SESSION['wantlist'][] = array($_SESSION['beadiwant'],$_SESSION['pathtothumb']);
//echo "The 13th bead is want is: {$_SESSION['wantlist'][13]} <br />";

// The code below shows me I can put two things by hand into an array, so why isn't it working to put the session variables in? 
$beads = array(0 => array('111b333cxt','path to photo of bead 111b333cxt'), 
			   1 => array('11355b6ctw','path to photo of bead 11355b6ctw'));
echo "<br /> BEAD EXPERIMENT: {$beads[0][0]} ---- {$beads[0][1]}<br />";
echo "<br /> BEAD EXPERIMENT: {$beads[1][0]} ---- {$beads[1][1]}<br />";

echo "<pre>";
print_r($_SESSION['wantlist']);
echo "</pre>";
//unset ($_SESSION['wantlist']);

if (isset($_SESSION['wantlist'])) {
	// print out the customer's want list
	foreach ($_SESSION['wantlist'] as $bead => $path) { 
		echo 'bead is: '.$bead.' path to it is: '.$path[$pt1][].'<br />';
	}
}
?>
<?php foreach ($_SESSION['wantlist'] as $item) { ?>
    <tr>
        <td class="name"><?php echo ($item); ?></td>
        <td class="thumbnail"><?php echo ('picture goes here'); ?></td>
    </tr>
    <p>
      <?php } ?> 
</p>
<table width="300" border="1" cellpadding="20">
      <caption>
        My Bead Want List
      </caption>
      <?php foreach ($_SESSION['wantlist'] as $item) { 
      	  echo('<tr>
      		<td class="name">'.$item.'</td>
      		<td class="thumbnail"><img width="87" height="87" src='.$_SESSION['pathtothumb'].' /></td>
        	</tr>'); }
       ?>
           
    </table>
    <p>     </p>
</body>

 

The code above now gives me this:

Fatal error: Cannot use [] for reading in wantlist.php on line 100

But even before that error, all I could get was a listing of the bead inventory number, with the thumbnail connected with the most recent bead choice duplicating itself in the table next to every one of the bead numbers.

 

Thanks for any help you can give, and if I can clarify my question let me know.

 

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.