Jump to content

Last 5 Searches Storing Array in Session


sheriff_bob

Recommended Posts

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);
?>

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']);
}

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.