Jump to content

ADD Page to "fav" list?? is it simple??


techiefreak05

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]

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.