Welcome to WebmasterWorld Guest from 220.127.116.11
What I am trying to achieve is to create a popular categories functionality on the site whereby I would like to list the top 6 categories according to the number of stories submitted for each of the categories.
So basically I have around 20 categories in all but I would like to display the top 6 and then a link to the rest of the categories. Now I've made start on this but I've been scratching my head on this one, and just need pointing in the right direction.
The code below shows that I get each total for each category, and place that in the array with the ncid for that category because I will need to query the categories table to get the category name, if you get what I mean.
Anyway here's the code:
// TABLE OF CATEGORIES
// QUERY TO COUNT THE NUMBER OF NEWS STORIES FOR EACH CATEGORY
$sql_total=mysql_query("select count(*) as total,tbl_news_categories.ncid,news_catname
group by tbl_news_categories.ncid
order by total desc");
// CREATE ARRAY TO STORE TOTAL FOR EACH CATEGORY - DON'T KNOW IF THIS IS THE RIGHT WAY OR NOT?
// TEST TO DISPLAY THE ARRAY
foreach ($ncids as $key => $val)
echo "$key = $val<br>";
Any help always appreciated.
If you do not need to get all results add
LIMIT 6 in the end, so it will be like:
order by total desc LIMIT 6");
Not sure if it is what you are looking, let me know please if it helps or not.