making history simple script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ownx
Forum Newbie
Posts: 2
Joined: Sun May 27, 2007 11:42 am

making history simple script

Post 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
:(
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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 />';
   }
}
ownx
Forum Newbie
Posts: 2
Joined: Sun May 27, 2007 11:42 am

Post 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 :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply