Kingw Posted March 26, 2009 Share Posted March 26, 2009 Hello! Well I am new here, I found this forum while searching for help in Google, lol, So hopefully somebody can help me out 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> "; } ?> Which produces * User - 12 * User - 10 * User - 4 * User - 2 * User - 1 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. Quote Link to comment https://forums.phpfreaks.com/topic/151194-solved-pull-information-from-2-databases-and-order-it/ Share on other sites More sharing options...
bluejay002 Posted March 26, 2009 Share Posted March 26, 2009 Check out this link: http://dev.mysql.com/doc/refman/5.0/en/join.html It discusses about JOIN and just about what you need. Quote Link to comment https://forums.phpfreaks.com/topic/151194-solved-pull-information-from-2-databases-and-order-it/#findComment-794253 Share on other sites More sharing options...
Kingw Posted March 26, 2009 Author Share Posted March 26, 2009 Honestly most of what the page said went over my head , But I got the script to do this # user4 - 4 # user4 - 4 # user2 - 2 # user2 - 2 # user2 - 2 # user2 - 2 # user2 - 2 # user2 - 2 # user2 - 2 # user2 - 2 # user2 - 2 # user3 - 3 # user4 - 4 # user7 - 7 # user7 - 7 # user7 - 7 # user7 - 7 # user7 - 7 # user3 - 3 # user7 - 7 # user2 - 2 # user7 - 7 # user7 - 7 # user7 - 7 # user7 - 7 # user7 - 7 # user7 - 7 # user4 - 4 But I want it to just Count them and post the amount there is like this # user7 - 12 # user2 - 10 # user4 - 3 # user3 - 2 But if I add the "COUNT(*)" It doesn't work... I'm not sure if it explained this at all, Maybe give me some tips? Quote Link to comment https://forums.phpfreaks.com/topic/151194-solved-pull-information-from-2-databases-and-order-it/#findComment-794369 Share on other sites More sharing options...
bluejay002 Posted March 26, 2009 Share Posted March 26, 2009 Can you post the latest query you have? Also, this one is more like a MySQL question rather than a PHP one. Anyway, I will leave this one for the modo to decide. If you can post the query that you have and the table structure of the two tables... so that I can have an idea about of the situation. But before that, you might want also to try this: SELECT T1.some_user_name, COUNT(T2.`user_id`) `total` FROM some_user_table AS T1 INNER JOIN completed AS T2 ON T1.`user_id` = T2.`user_id` GROUP BY T1.`user_id` ORDER BY T1.`user_id` DESC Quote Link to comment https://forums.phpfreaks.com/topic/151194-solved-pull-information-from-2-databases-and-order-it/#findComment-794406 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.