bcode Posted August 26, 2009 Share Posted August 26, 2009 This is my problem I am trying to put $thumbArray into a session but I can only get one of the images to go into the session? Then when I am successful how do I grab the images out of the session. Any help would be much appreciated I am running blind not knowledgeable in this. foreach($dataArray as $item_num => $info){ $customer_id = $id; $item_id = $info['id']; $sql = "SELECT * FROM table WHERE id='$item_num'"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $thumbArray = array();//THIS ARRAY RIGHT HERE $thumbArray['image'] = $thumb = $row['image']; $title = $row['title']; $price = $row['price']; } $_SESSION['filenames'] = $thumbArray; NEXT PAGE retrieving the session foreach($_SESSION['filenames'] as $key=>$value) { // this is what I have started but I need to grab them individually HOW DO I DO THAT and put them into something like <a href="url/something.php?L=filename goes here" > } Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted August 26, 2009 Share Posted August 26, 2009 $thumbArray['image'] = $thumb = $row['image']; This will assign the value in $thumb to $thumbArray['image'] every time through the loop. In other words, you are storing the value in the same place every time through the loop and each successive time through the loop you are replacing the existing value. If you want to append items onto the end of an array you use empty braces, []: $arr = array(); $arr[] = 1; $arr[] = 'larry'; $arr[] = 3.14; // $arr is an array with: 1, 'larry', 3.14 $thumbArray[] = $thumb = $row['image']; // ~OR~ $thumbArray['image'][] = $thumb = $row['image']; And unless you're using it for something else, and I don't see that you are, the extra $thumb = is not needed. Quote Link to comment Share on other sites More sharing options...
bcode Posted August 26, 2009 Author Share Posted August 26, 2009 I tried what you had said but I am printing the Session after that code and it says [filenames]=>Array([image]=>Array([0]=>whatever.jpg)) It doesnt seem to be outputting both files in the array only one, but this time it has the index # on it foreach($dataArray as $item_num => $info){ $customer_id = $id; $item_id = $info['id']; $sql = "SELECT * FROM table WHERE id='$item_num'"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $thumbArray = array();//THIS ARRAY RIGHT HERE $thumbArray['image'][] = $thumb = $row['image']; $title = $row['title']; $price = $row['price']; } $_SESSION['filenames'] = $thumbArray; Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted August 26, 2009 Share Posted August 26, 2009 This line initializes $thumbArray into an empty array. $thumbArray = array();//THIS ARRAY RIGHT HERE You've placed it inside the loop. Do you see a problem with that? Quote Link to comment Share on other sites More sharing options...
bcode Posted August 26, 2009 Author Share Posted August 26, 2009 thank you!!!! That was dumb of me I put it in there to consolidate the code for the forum Thank you again for pointing that out I would of scratched my head for awhile till i thought of that Quote Link to comment 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.