[thelist] RE: php array cleverness needed
HUTTON III, WILLIAM J.
WJHUTTONIII at energy-northwest.com
Tue Sep 2 18:02:42 CDT 2003
It's always best to be clever in the query, if possible. ;)
Try this;
SELECT TOP 5 country_name FROM country WHERE country_count > 0 ORDER BY country_count, country_name
That will give you the countries with the highest counts, and exclude countries with zero counts. I built a quick test table, and got back only the US and Canada.
The way I'd do it, is to use two arrays, recordsets, rocks, whatever your flavor or programming dictates; one array for the top five, and a second array for the complete list.
You can use sql properties like @@rowcount to find the number of rows returned, so you could programmatically assign the text to say "Top 2 Countries Clicked", and still limit the results to up to five with the TOP keyword.
Hope that helps!
Will
More information about the thelist
mailing list