grlayouts Posted July 20, 2008 Share Posted July 20, 2008 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. Quote Link to comment Share on other sites More sharing options...
DarkerAngel Posted July 20, 2008 Share Posted July 20, 2008 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. Quote Link to comment Share on other sites More sharing options...
grlayouts Posted July 20, 2008 Author Share Posted July 20, 2008 print? Quote Link to comment Share on other sites More sharing options...
DarkerAngel Posted July 20, 2008 Share Posted July 20, 2008 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']); ?> Quote Link to comment 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.