sheriff_bob Posted April 23, 2007 Share Posted April 23, 2007 I've been working on this all night and I'm loosing my mind. I'm trying to figure out how to store 5 sequential searches with a session, with each new search knocking the old search off the array. Thank you for your help. Link to comment https://forums.phpfreaks.com/topic/48229-last-5-searches-storing-array-in-session/ Share on other sites More sharing options...
Guest prozente Posted April 23, 2007 Share Posted April 23, 2007 Look at array_shift http://us2.php.net/manual/en/function.array-shift.php Link to comment https://forums.phpfreaks.com/topic/48229-last-5-searches-storing-array-in-session/#findComment-235752 Share on other sites More sharing options...
boo_lolly Posted April 23, 2007 Share Posted April 23, 2007 to illustrate prozente's advice, it'd probably look something like this: <?php $sql = " SELECT * FROM your_table WHERE id = '42' "; function session_search($var){ if(array_key_exists($_SESSION['searches'][4]){ array_shift($_SESSION['searches']); $_SESSION['searches'][] = $yourSearchInfo); }else{ $_SESSION['searches'][] = $yourSearchInfo; } } session_search($sql); ?> Link to comment https://forums.phpfreaks.com/topic/48229-last-5-searches-storing-array-in-session/#findComment-235791 Share on other sites More sharing options...
sheriff_bob Posted April 23, 2007 Author Share Posted April 23, 2007 Thanks for the help guys. I"m currently not storing any of this information in a database. I created this bit of code here, but the problem is it only cycles the newest entry into the position. Instead of leaving the other values. So it does 1. Hello 2. 3. 4. 1. 2.Goodbye 3. 4. Instead of 1. Hello 2. Goodbye 3. 4. session_start(); if(!isset($_SESSION['x'])){ $_SESSION[0]=$_POST['id']; $_SESSION['x']=1; } elseif($_SESSION['x']==1){ $_SESSION[1]=$_POST['id']; $_SESSION['x']=2; } elseif($_SESSION['x']==2){ $_SESSION[2]=$_POST['id']; $_SESSION['x']=3; }elseif($_SESSION['x']==3){ $_SESSION[3]=$_POST['id']; unset($_SESSION['x']); } Link to comment https://forums.phpfreaks.com/topic/48229-last-5-searches-storing-array-in-session/#findComment-235798 Share on other sites More sharing options...
boo_lolly Posted April 23, 2007 Share Posted April 23, 2007 why don't you use my code? Link to comment https://forums.phpfreaks.com/topic/48229-last-5-searches-storing-array-in-session/#findComment-235804 Share on other sites More sharing options...
sheriff_bob Posted April 23, 2007 Author Share Posted April 23, 2007 I'm sorry I'm just a little confused by it. But let me give it a try Link to comment https://forums.phpfreaks.com/topic/48229-last-5-searches-storing-array-in-session/#findComment-235807 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.