Page 1 of 1
making history simple script
Posted: Sun May 27, 2007 11:49 am
by ownx
Hi,
i m looking for a good algoretem or Tutorial to make a history script, i tryed to make it in few ways but its too complicated
let me explain more about it
i want a script for my site so registered users can see what last 10 pages they viewed and save them in a database
and it will be based on (first in first out) if anyone can help me with good way

or got any good Tutorial thanks

Posted: Sun May 27, 2007 12:18 pm
by s.dot
Well, you'd have to save the page name in a database table each time a registered user views a page.
Perhaps:
Code: Select all
mysql_query("INSERT INTO `pageviews` (`user`,`page`) VALUES ('$user', '".basename($_SERVER['PHP_SELF'])."')") or die(mysql_error());
Then to display them to the user, in the order you mentioned:
Code: Select all
$r = mysql_query("SELECT `page` FROM `pageviews` WHERE `user` = '$user' ORDER BY `id` DESC LIMIT 0, 10") or die(mysql_error());
if(mysql_num_rows($r) == 0)
{
echo 'You haven\'t viewed any pages yet.';
} else
{
while($a = mysql_fetch_assoc($r))
{
echo $a['page'].'<br />';
}
}
Posted: Sun May 27, 2007 1:03 pm
by ownx
but in
Code: Select all
mysql_query("INSERT INTO `pageviews` (`user`,`page`) VALUES ('$user', '".basename($_SERVER['PHP_SELF'])."')") or die(mysql_error());
you will save all the pages that this user have viewed and it will just save useless data in the database that i dont use it
i wanted to have script to save just the latest 10 pages and delete the older ones thats why i mentioned the (first in first out method)
thanks for replaying to my post

Posted: Sun May 27, 2007 4:29 pm
by feyd
You will need logic added to erase older entries. It's not too difficult, but we would like to see you attempt it.