Jump to content

[SOLVED] Pull information from 2 databases and order it?


Kingw

Recommended Posts

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.

Link to comment
Share on other sites

Honestly most of what the page said went over my head  :P, 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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.