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
https://forums.phpfreaks.com/topic/115733-2-tables/
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
https://forums.phpfreaks.com/topic/115733-2-tables/#findComment-594960
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
https://forums.phpfreaks.com/topic/115733-2-tables/#findComment-594975
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.