Page 1 of 1

PHP Logic problem

Posted: Mon Aug 22, 2005 8:53 pm
by funsutton
I am suffering from Brain-Block, and can't figure out how to code this. I'll try and keep my explaination short.

What I am trying to do:
I have a weather website and I am trying to display the last 3 searches the visitor has made, using cookies to read in and store the data. I want to make sure that each of the last 3 searches displayed is unique, and not a duplicate. But I can't figure out the logic on how to go from cookie to cookie, writing the last visit in the appropriate cookie. I know this sounds simple, but it doesn't seem that way to me. Can anyone help? BTW, I would show you what I have, but I don't have any code yet to make this work, as I can't figure out where to start.

Brian

Posted: Mon Aug 22, 2005 9:27 pm
by feyd
unless for some reason you're storing a lot of data, you could keep the search data in a single cookie, thus making the bookkeeping easier :)

Posted: Mon Aug 22, 2005 11:11 pm
by d3ad1ysp0rk
As feyd pointed out, it'd be a simple:

Code: Select all

<?php
$results = array();
$i = 0;
while (count($results) < 3 && isSet($_COOKIE['searches'][$i+1])){
  if(!in_array($_COOKIE['searches'][$i+1]),$results)){
    $results[] = $_COOKIE['searches'][$i+1];
  }
}
echo "<pre>";
print_r($results);
echo "</pre>";
?>