Jump to content

[SOLVED] Retreiving array from a session?


Solarpitch

Recommended Posts

Hey,

 

Heads melted working with arrays all day! I have this piece of code below that will store the user's favorites items on the site. It basically adds the item id to the session array.

 

I just want to know how I can then list all the item id's from that session array to store in a variable? cheers

 


if(isset($_GET['fav']))
{
$_SESSION['favs'][] = $property_id;

foreach($_SESSION['favs'] as $key=>$val) {
}

}

// Here's how I can list them and print them to screen, but this is no good as each item id in the session array will need to be put into an sql query. So I need to individually pick each id out of the array.

while (list(,$v) = each ($favs)) 
{
echo $v
} 

Link to comment
Share on other sites

<?
$_SESSION['favs'][] ='teng1';
$_SESSION['favs'][] ='teng2';
$_SESSION['favs'][] ='teng3';
$_SESSION['favs'][] ='teng4';
$_SESSION['favs'][] ='teng5';

foreach($_SESSION['favs'] as $key=>$val){
echo "$"."_SESSION"."[favs][".$key ."]=".$val;
echo '<br>';
}
?>

 

see this sample

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.