Solarpitch Posted November 14, 2007 Share Posted November 14, 2007 Hey guys, In the below script I am trying to add the property_id to an array every time the page is loaded. So if fav is set, I want to add the is of that property to an array and hold that array in a session. This is wrong but its what I was trying... $property_id = $_GET['property_id']; if(isset($_GET['fav'])) { $faves = array ($fav); session_register('faves'); } Quote Link to comment Share on other sites More sharing options...
Daukan Posted November 14, 2007 Share Posted November 14, 2007 I'm not exactly sure what you are asking but this how you would make an array with a session var <?php $property_id = $_GET['property_id']; // makes a numerical keyed array called property_ids $_SESSION['property_ids'][] = $property_id; //uses the property id as the key $_SESSION[$property_id] = $favs; ?> BTW session_register is depreciated. Use use $_SESSION = $value; to set a session var Quote Link to comment Share on other sites More sharing options...
Solarpitch Posted November 14, 2007 Author Share Posted November 14, 2007 Cheers for that. When the page reloads or evrytime fav is set with a new value, I want that value to be added to the array. So say the user reloaded the page while viewing different property.. and they all had id's 465, 36, 125, 14 .. I want each of these to be added to the array each time this happens. Then I can loop through the array and display all the user's favorites based on that id's. Quote Link to comment Share on other sites More sharing options...
Daukan Posted November 14, 2007 Share Posted November 14, 2007 I didn't test it but it should work <?php $_SESSION['favs'][] = $property_id; foreach($_SESSION['favs'] as $key=>$val) { echo $val; } ?> Quote Link to comment Share on other sites More sharing options...
Solarpitch Posted November 14, 2007 Author Share Posted November 14, 2007 Perfect. Thanks a mill! 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.