Hi,
Wempy helped me out with this code the other day and all was working fine.... except I just changed the cateogry id in my categories table to 'text' from 'interger' and added a 0 in front of all the single digit categories. For example 01020304 was 1020304.
I had to do this as 01 is the first layer of my categories, 02 is the second, 03 is the third etc.
Now only categories without a leading 0 will store in the cookie. If I choose a cateogry with a leading 0, it wipes the cookie.
see www.argyllnewmedia.co.uk/marketplace2/
sign in u: haggis p: haggis to reveal the favourite categories on the front page.
<?
// get the pages array out of the cookie, as a string
$pages_string=$_COOKIE["pages_arr"];
// convert the string back to an array
$pages=unserialize($pages_string);
// set flag for later testing
$bflag=false;
if(!isset($pages))
{
// $pages does not exist yet so create it
$pages=array();
}
else
{
if(!is_array($pages))
{
// $pages exists but it isn't an array, so delete it
unset($pages);
// and re-create it as an array
$pages=array();
}
}
// reset the array pointer to the start of the array
reset($pages);
// iterate through the array to see if it already contains $id
while(list($key,$val)=each($pages))
{
if($key==$id)
{
// increment page count
$pages[$key]++;
// set flag to say that page is in array
$bflag=true;
// jump out of loop
break;
}
}
// test to see if page was found in array
if(!$bflag)
{
// it wasn't found so add this page to the array
$pages[$id]=1;
}
// right, now turn the array into a string
$pages_string=serialize($pages);
// so that it can be sent to the user as a cookie
setcookie("pages_arr", $pages_string, time()+999999);
?>
Any idea's where it doesn't like the leading 0?
Cheers
Asa