Jump to content

2 tables.


grlayouts

Recommended Posts

TABLE ONE

 

attack who type unit amount

427  12406  3  0  3237705

 

TABLE TWO

 

id username handle

12406 megb    tnuKapuS

 

hi i have two tables. what i want is it to order it by the highest ammount in table one then print out that ammount but match the 'who' in table 1 to 'id' in table two and print that..

 

so like

 

most: 3237705 user megb.

 

 

Link to comment
Share on other sites

This really has nothing to do with PHP and should have been posted in the MySQL forum, but

 

SELECT attack.table1, who.table1, type.table1, unit.table1, amount.table1, id.table2, username.table2, handle.table2
FROM table1, table2
WHERE who.table1 = id.table2
ORDER BY amount.table1

 

That's just something rough though but it should work.

Link to comment
Share on other sites

Well I'm sorry for one I had my code backwards a little bit, this will output exactly what you want (from the post), though I don't know the table names that you use so I'm going to sub table1 and table2 in accordance to your first post.

 

<?php
$query = "SELECT table1.amount, table2.username FROM table1, table2 WHERE table1.who = table2.id ORDER BY amount DESC LIMIT 1"
$sql = mysql_query($query);
$array = mysql_fetch_array($sql);
echo("most: ".$array['amount']." user ".$array['username']);
?>

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.