Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Favourites List stored via cookies

Status
Not open for further replies.

jgd12345

Technical User
Joined
Apr 22, 2003
Messages
124
Location
GB
Hi I was wondering how I could do the following, I have loads of bands with a unique field id. I wish to have it so that users on the site an add bands to there favourites and then they can view their favourites. Currently I have done the links so that it links to a file favourites.php?bid=$bid.

I now need to set the cookies, and do some way of displaying them.

I would be greatful if you could help. Thanx
 
Anyone with any ideas?
 
Hi, thanx for your reply, I understand the basics of cookies so I tried the following. It checks if the cookie exists and if not creates it:

// I put it as a function because it will be used more than once
function send_cookie($name, $value) {
global $cookiepath, $cookiedomain, $$name;

setcookie($name, $value, time() + 31104000, $cookiepath, $cookiedomain); // expires in one year
$$name = $value;
}

if($favourite[$tid] != "tab") {
send_cookie("favourite[$tid]", 'tab');
}

and the following should print out the list:

$query = mysql_query("SELECT * FROM $flixon_tabs ORDER BY songname");

while($tab = mysql_fetch_array($query)) {
if($favourite[$tab[id]] == "tab") {
echo ''.$tab[songname].'<br>';
}
}

But it doesn't work, something goes wrong along the way. I would be greatful if you could clear this up as it has been bothering me for a while now. Thanx
 
Are you the only person who TRYS to help on here (I know that's not gonna do me no good if you're gonna help). It's not too difficul to see but you will notice that send_cookie(&quot;favourite[$tid]&quot;, 'tab'); runs the function send_cookie which should create the cookie favourite[id] when the variable $tid is passed to the form. (sets the cookie value = tab)

Then I already know that if you create the cookie then when you goto a page you can view that variable by putting $nameofvariable which is where the check comes in. Because the cookie value was set to tab it checks it the variable is equal to tab and if so prints it out. But it's printing out jibberish.

Please help. Thanx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top