Jump to content

Arrays into session?


bcode

Recommended Posts

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" >

    }

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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;

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.