ordering

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thesimon
Forum Commoner
Posts: 40
Joined: Sun Mar 13, 2005 9:44 pm

ordering

Post by thesimon »

sorry if this is a database question, however i am not exactely sure if the solution is in the php or the mysql query itself.

I have a table that stores hits to press releases

ie: (Key | TimeDate | IP Address | Press Release ID)

Now i need to group by (press release id), and then count how many rows share each (press release id), then order the records in a table by the amount of rows in the database table per Press Release,

In other words i want to show the 5 Most popular press releases on the page.

pre-emtive thanks
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Post by Stryks »

You should be able to get the results with something fairly simple.

A query along the lines of ...

Code: Select all

SELECT `Release_ID`, count(`Release_ID`) AS `rank` FROM `tbl_hits` GROUP BY `Release_ID` ORDER BY `rank` DESC LIMIT 5
... should do the trick if you simply want the top 5 release ID's.

You could link these results back to the press release table if you want to pull back titles or other info.

Maybe this should be moved to databases. 8)
Post Reply