Reply to Re: Sorting by Popularity?

Your name:

Reply:


Posted by NC on 10/22/40 11:39

ReGenesis0@aol.com wrote:
>
> I guess, I must ask again- is there an elegant way to teack 'just
> the hits in the last week,' essentiallg dropping the 'back-end' hits
> as they elapse past the hit-time, WITHOUT keeping an individual
> record of all hits over the course of the week?

You could try daily totals... Say, you have a MySQL table called hits:


id (INT): Page ID
date (DATE): Day for which you need to know the number of hits
hits (INT): Hit count

The table's primary key is a two-column index based on `id` and `date`.


Every time a page is accessed, it does something like this:

$date = date('Y-m-d');
$id = [Page ID here];
$query = "UPDATE `hits` SET `hits` = `hits` + 1 " .
"WHERE `id`=$id AND `date`='$date' ";
mysql_query($query);

Summing up the daily totals for the last seven days then becomes rather
trivial:

SELECT id, SUM(hits) AS score
FROM hits
WHERE date >= '[the first day of counting]'
GROUP BY id
ORDER BY score DESC;

Chees,
NC

[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

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