I am really new to MySQL and am Trying to teach myself But im stuck on this Im not sure how to explain what I am trying to do here, but Here is what I have so far using code <? include"mysql.php"; $getoffers=mysql_query("SELECT COUNT(*) `user_id` FROM `completed` GROUP BY `user_id` ORDER BY `user_id` DESC",$c); while($off=mysql_fetch_array($getoffers)) { print" <li>User - {$off['user_id']}</li> "; } ?> Code (markup): Which produces Which is exactly what I want. EXCEPT, In the "User" part I want to display the Username of the person who has completed that amount, ok, now your thinking idiot so just put {$off['username']}. The thing is The Usernames are not in the table, only the User ID #s, the Usernames are in their own table "Users" So what I need is to figure out how to pull the the Usernames from the Users Table, and Sort them in the same way as the number of completed, Now the User ID # is in both tables, Could I use that? I hope that makes scene, If not I can post in more detail what I need.
try this: SELECT COUNT(*), completed.user_id, Users.username FROM completed,Users WHERE completed.user_id=Users.user_id GROUP BY completed.user_id ORDER BY completed.user_id DESC Code (markup): this should give you the fields: count user_id and username
Thank you for your help, That gets it to do half of what I want I used this code <? include"mysql.php"; $getoffers=mysql_query("SELECT COUNT(*), completed.user_id, users.username FROM completed,users WHERE completed.user_id=users.id GROUP BY completed.user_id ORDER BY completed.user_id DESC",$c); while($off=mysql_fetch_array($getoffers)) { print" <li>{$off['username']} - {$off['user_id']}</li> "; } ?> Code (markup): and it Gives me User7 - 7 User4 - 4 User3 - 3 User2 - 2 It is showing the User ID # instead of the amount of times it is in that Table
if you want to show the number of times change SELECT COUNT(*), to SELECT COUNT(*) AS times, then use {$off['times']} instead of {$off['user_id']}