nathanmaxsonadil Posted August 18, 2007 Share Posted August 18, 2007 I know this is kinda crazy but I need it I have one table that lists name's and I have another table that has the name's and points I want to know how to list the name's of the first table by the points of the second table Quote Link to comment https://forums.phpfreaks.com/topic/65629-solved-getting-from-one-table-listing-from-another/ Share on other sites More sharing options...
Masna Posted August 18, 2007 Share Posted August 18, 2007 If the table that contains points also contains names, you should only need to work with one table. SELECT `names` FROM `table` ORDER BY `points` DESC Quote Link to comment https://forums.phpfreaks.com/topic/65629-solved-getting-from-one-table-listing-from-another/#findComment-327751 Share on other sites More sharing options...
nathanmaxsonadil Posted August 18, 2007 Author Share Posted August 18, 2007 I have 2 table's because no all the names are going to be listed in the first table Quote Link to comment https://forums.phpfreaks.com/topic/65629-solved-getting-from-one-table-listing-from-another/#findComment-327755 Share on other sites More sharing options...
BlueSkyIS Posted August 18, 2007 Share Posted August 18, 2007 SELECT `names` FROM `table` WHERE `names` IN (SELECT `names` FROM `othertable`) ORDER BY `points` DESC Quote Link to comment https://forums.phpfreaks.com/topic/65629-solved-getting-from-one-table-listing-from-another/#findComment-327777 Share on other sites More sharing options...
nathanmaxsonadil Posted August 18, 2007 Author Share Posted August 18, 2007 thanks Quote Link to comment https://forums.phpfreaks.com/topic/65629-solved-getting-from-one-table-listing-from-another/#findComment-327783 Share on other sites More sharing options...
nathanmaxsonadil Posted August 30, 2007 Author Share Posted August 30, 2007 in phpmyadmin it works but in php it does not here's my code $sql = "SELECT `username` FROM `users` WHERE `username` IN (SELECT `need` FROM `tb`) ORDER BY `points` DESC"; $result = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result) > 0) { echo "<ul>"; while ($row = mysql_fetch_assoc($result)) { echo "<li>{$row['need']}</li>"; } echo "</ul>"; } Quote Link to comment https://forums.phpfreaks.com/topic/65629-solved-getting-from-one-table-listing-from-another/#findComment-337506 Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 What "does not work"? What are you expecting and what do you get? Quote Link to comment https://forums.phpfreaks.com/topic/65629-solved-getting-from-one-table-listing-from-another/#findComment-337508 Share on other sites More sharing options...
nathanmaxsonadil Posted August 30, 2007 Author Share Posted August 30, 2007 it only display an empty ul... but in phpmyadmin it display's the username.... Quote Link to comment https://forums.phpfreaks.com/topic/65629-solved-getting-from-one-table-listing-from-another/#findComment-337619 Share on other sites More sharing options...
Illusion Posted August 30, 2007 Share Posted August 30, 2007 U didn't select the 'need' column in ur query .........how does $row['need']? Quote Link to comment https://forums.phpfreaks.com/topic/65629-solved-getting-from-one-table-listing-from-another/#findComment-337625 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.