Jump to content

Recommended Posts

the database is your friend, just create a datbase named favorites or something and then when a user clicks the 'Add to favorites' it inserts the current page(path), his userid(need this to load it on his profile/homepage page) to the database, and on his profile page you just start rollin' it out!
I would suggest that you'd be using INSERT statements rather than UPDATES...assuming you have a table in your datbase with a user field and a url field, to add a favourite:
[code]
<?php
$url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$sql="INSERT INTO yourtable SET url='$url',name='$user'";
mysql_query($sql);
?>
[/code]

And then to generate all of their favourites:
[code]
<?php
$sql = "SELECT * FROM yourtable WHERE user='$user'";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)){
echo $row['url'];
echo "<br />";
}
?>
[/code]

Of course, i expect you'd want to modify the output to make it look a bit nicer, but thats the general idea.
ron, don't you mean INSERT? How can you update if the page does not already exists? Thus something like:

[code]
$Userid = $_SESSION['userid']; // or something..
$Url = eval("http://" . $_SERVER['HTTP_POST'] . $_SERVER['PHP_SELF']);// Does php_self also includes queries? if not add . $_SERVER['QUERY_STRING'];

$Sql = "INSERT INTO `favorites` (`Url`, `User_id`) VALUES ('$Url', '$Userid');";
[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.