Reply to Re: [PHP] Last visitors

Your name:

Reply:


Posted by Ken on 04/19/05 16:30

On 4/19/05, Ryan A <ryan@coinpass.com> 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.
>
> 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
>
>

Well... I had a thought...
you can do a count query

SELECT user, count(visitor) as visitor_count FROM profile_visit GROUP BY user;
then you have a recordset like...

user count(visitor)
adam 9
ben 12

grab the recordset in php

while($object= mysql_fetch_object($result))
{
if($object->visitor_count > 10)
{
//SELECT the least recent visit_time
$query = "SELECT visit_time FROM profile_visit WHERE user=' "
..$object->user. " ' LIMIT 9,10";
$result = mysql_query($query);
list($visit_time) = mysql_fetch_row($result);

//DELETE anything that is less recent than $visit_time, the
visit time for anything before the 10th most recent visit.
$query = "DELETE FROM profile_visit WHERE user=' "
..$object->user." AND visit_time < '$visit_time'";
}
}

it's probably not very streamlined, but it should work.
Try posting on devshed as well. They are very quick and good with this
kind of stuff
forums.devshed.com

HTH

Ken

execute this in cron, once a day or something like that...

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация