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
https://forums.phpfreaks.com/topic/77549-solved-retreiving-array-from-a-session/
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

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.