Forum Moderators: coopster
I've been tearing out my hair trying to get my latest project online. I have a user based site and some of the info is being stored in a mysql table where each record is identified by the user's username. I want to generate a list to be displayed online that shows the top ten users who have the most records. Basically just a list of the the most frequently occuring records in the table. Right now I am using the following SQL query:
$sql = "SELECT user, COUNT(*) as number FROM tablename GROUP BY user ORDER by number desc LIMIT 10";
$result = @mysql_query($sql, $connection) or die("Couldn't Execute Query");
I'm getting data back but am not sure if it is correct or exactly how to display it on the page. I typically use:
while ($row = mysql_fetch_array($result)) {}
but am not sure how to extract the count for each record using this. Any help you could give would be GREATLY appreciated!
Thanks!
Nick LAdd
while ($row = mysql_fetch_array($result)) {
print "$row[0]: $row[1]<br>";
} or alternatively:
while ($row = mysql_fetch_array($result)) {
print "$row['user']: $row['number']<br>";
} I recommend the excellent PHP online documentation:
[php.net...]
(edit: correction)