Re: Last visitors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tuesday 19 April 2005 16:27, Ryan A wrote:
> > I am not checking for the last people logged in, I want to see the last
> > people who have viewed the profile...
> > each profile will have its own last "10 people visited"
>
> /*
> ah! i see. sorry for misunderstanding you.
> perhaps on the script for the profiles page, the logic should be like:
>
> profile for user: adam
>
> if the browsing user is logged in: (for example the browsing user is ben)
>       insert into the database that ben has seen adam's profile
> end if....
>
> and your table in the database can be:
>
> user       visitor      time_of_visit
> adam      ben         1290122141 (unix timestamp)
>
> then you can query it on the database for each user.
>
> SELECT * FROM profile_visits WHERE user='adam' ORDER by time_of_visit
> DESC LIMIT 10
> As for cleaning up... that's the bit that I can't figure out myself :(.
> */
>
> Hey,
> Thanks for replying.
>
> > ah! i see. sorry for misunderstanding you.
>
> No problem, I guess i didnt explain it well enough, and you dont have to
> help me but you are trying, so thank you.
>
> > As for cleaning up... that's the bit that I can't figure out myself :(.
>
> exactly, I came to the same part as you....but then i would have a LOT of
> wasted records without the cleanup... just cant figure it out.

You can store only 10 records for each user by using the following logic:

mysql> show create table profile_log\G
*************************** 1. row ***************************
       Table: profile_log
Create Table: CREATE TABLE `profile_log` (
  `profile_id` int(10) default NULL,
  `user_id` int(10) default NULL,
  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update 
CURRENT_TIMESTAMP
) ENGINE=MyISAM DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

When you create a profile you fill 10 blank records with timestamp 0000-00-00 
00:00:00.

Then if a user sees a profile:

PSEUDO SQL:

$SQL = "UPDATE profile_log SET user_id=".$userId." WHERE profile_id=".
$profileId." ORDER BY timestamp ASC LIMIT 1";

This way you:
1. automatically get the new timestamp
2. have no more than 10 records per user.

>
> Thanks,
> Ryan
>
>
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.308 / Virus Database: 266.9.16 - Release Date: 4/18/2005

-- 

Cyberly yours,
Petar Nedyalkov
Devoted Orbitel Fan :-)

PGP ID: 7AE45436
PGP Public Key: http://bu.orbitel.bg/pgp/bu.asc
PGP Fingerprint: 7923 8D52 B145 02E8 6F63 8BDA 2D3F 7C0B 7AE4 5436

Attachment: pgpfjO3YAzfaS.pgp
Description: PGP signature


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux