graham23s Posted August 13, 2007 Share Posted August 13, 2007 Hi Guys, users on my site can vote 1-10 on different profiles, which get increments (by what ever they vote) ina `total` table, so if i vote 10 and someone else votes 10 thats 20 and so on. im trying to display the top 10 rated profiles using the count feature but im getting no joy what i have so far is this: $query5 = "SELECT `total`, COUNT(*) AS `count` FROM `profiles` GROUP BY `total` ORDER BY `count` DESC LIMIT 10"; $result5 = mysql_query($query5); echo '<table width="60%" border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" /> <tr> <th bgcolor="#004E98" colspan="2"><font color="#ffffff">Top 10 Rated Profiles</font></th> </tr> <tr> <td width="30%" bgcolor="#004E98" align="center"><font color="#ffffff"><b>Profile Name</b></font></td><td width="30%" bgcolor="#004E98" align="center"><font color="#ffffff"><b>Average Rating</b></font></td> </tr>'; while ($row = mysql_fetch_array($result5)) { // get the usernames clickable...///////////////////////////////////////////// $name = $row['file_name']; $total = $row['total']; $id_3 = $row['id']; echo '<tr><td align="center"><a href="profile.php?id='.$id_3.'">'.$name.'</a></td><td align="center">'.$total.'</td></tr>'; } echo "</table><br /><br />"; so it kinda displays: graham 50 david 45 etc any help would be appreciated Graham Quote Link to comment https://forums.phpfreaks.com/topic/64717-solved-counting-statistics-from-mysql/ Share on other sites More sharing options...
akitchin Posted August 13, 2007 Share Posted August 13, 2007 are you storing `total` for each vote made? or is the `total` the sum of all votes submitted so far? if the latter, where are you storing the number of votes that have been made? Quote Link to comment https://forums.phpfreaks.com/topic/64717-solved-counting-statistics-from-mysql/#findComment-322738 Share on other sites More sharing options...
reages Posted August 13, 2007 Share Posted August 13, 2007 ...but im getting no joy... can you be more specific? so it kinda displays: graham 50 david 45 etc so is it safe to assume that your code is able to sum the votes and display the profile in the order of highest-to-lowest vote, w/o duplicate profile? regards. Quote Link to comment https://forums.phpfreaks.com/topic/64717-solved-counting-statistics-from-mysql/#findComment-322747 Share on other sites More sharing options...
graham23s Posted August 13, 2007 Author Share Posted August 13, 2007 Hi Guys, Thanks for the input just fixed it thanks again. Graham Quote Link to comment https://forums.phpfreaks.com/topic/64717-solved-counting-statistics-from-mysql/#findComment-322765 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.