Advanced Toplist Tasks
By Paul
By Paul
In a toplist, the 'condition' section is the most powerful part. This allows you to select which links, categories, comments or members you need to show. The condition uses MySQL syntax, and this allows many options. (For those who know MySQL: the condition is placed after "WHERE" in the MySQL SELECT query.)
Suppose you need to show all links from between two particular dates. There isn't any 'date' field in the database... the 'time' field is in the form of a Unix timestamp (the number of seconds since 1970). So instead you need to take advantage of MySQL's integrated functions. This condition would grab everything from October 4th through 6th of 1997:
time > UNIX_TIMESTAMP('1997-10-04 00:00:00') AND time < UNIX_TIMESTAMP('1997-10-07 00:00:00')
There are many other MySQL functions listed in the MySQL manual at http://www.mysql.com/doc/en/ . Date and time functions are at http://www.mysql.com/doc/en/Date_and_time_functio...
To get the current time, use UNIX_TIMESTAMP() with no arguments passed. Thus to get all links from the last 10 days, your condition would be
time > (UNIX_TIMESTAMP() - 60*60*24*10)
The last portion of this is simply the number of seconds which exist in 10 days: 60 seconds per minute times 60 minutes per hour times 24 hours per day times 10 days.
Another task: Suppose you want to make a toplist of all links in category #1 and all its subcategories. Just the category alone is easy enough by supplying a condition catid=1. Including links from subcategories of 1 takes a more complicated condition: catid=1 OR parentids LIKE '%|||1|||%'. This means where the category is 1 or one of the category's parents is 1. The full config line for this toplist:
<CONFIG>links,time,5,descending,catid=6 OR parentids LIKE '%|||6|||%'</CONFIG>
Suppose you need to show all links from between two particular dates. There isn't any 'date' field in the database... the 'time' field is in the form of a Unix timestamp (the number of seconds since 1970). So instead you need to take advantage of MySQL's integrated functions. This condition would grab everything from October 4th through 6th of 1997:
time > UNIX_TIMESTAMP('1997-10-04 00:00:00') AND time < UNIX_TIMESTAMP('1997-10-07 00:00:00')
There are many other MySQL functions listed in the MySQL manual at http://www.mysql.com/doc/en/ . Date and time functions are at http://www.mysql.com/doc/en/Date_and_time_functio...
To get the current time, use UNIX_TIMESTAMP() with no arguments passed. Thus to get all links from the last 10 days, your condition would be
time > (UNIX_TIMESTAMP() - 60*60*24*10)
The last portion of this is simply the number of seconds which exist in 10 days: 60 seconds per minute times 60 minutes per hour times 24 hours per day times 10 days.
Another task: Suppose you want to make a toplist of all links in category #1 and all its subcategories. Just the category alone is easy enough by supplying a condition catid=1. Including links from subcategories of 1 takes a more complicated condition: catid=1 OR parentids LIKE '%|||1|||%'. This means where the category is 1 or one of the category's parents is 1. The full config line for this toplist:
<CONFIG>links,time,5,descending,catid=6 OR parentids LIKE '%|||6|||%'</CONFIG>
Rating:




4/5 based on 1 vote. The median rating is 4.
Rate this article:
Submitted: 03/10/04 (Edited 07/28/04)
Description: Exploring some of the more complicated possibilities of toplists.
Views:
1524 views. Averaging 1 per day.
In the most recent 30 day period, there've been 1 views.

Print
E-Mail