Pain Posted November 21, 2011 Share Posted November 21, 2011 Hello. I am trying to display info from two tables with this code. <?php $query = mysql_query("SELECT users.username, users2.username FROM users INNER JOIN users2 ON users.id = users2.id"); $numrows = mysql_num_rows($query); if ($numrows != 0) { while ($row = mysql_fetch_assoc($query)) { $username = $row['username']; echo $username . "<br />"; } } ?> However it displays info only from one db (users). I suppose there's something wrong with <?php ... while ($row = mysql_fetch_assoc($query)) { $username = $row['username']; echo $username . "<br />"; } ... ?> Any help will be appreciated. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/251556-inner-join-display-info-on-the-web/ Share on other sites More sharing options...
jeff5656 Posted November 21, 2011 Share Posted November 21, 2011 "$username = $row['username'];" the query doesn't know which table this refers to. you have to say select users.username as username1, users2.'usersname2'as users2... ans then in the while look say $row[username1] or $row['usersname2'] Quote Link to comment https://forums.phpfreaks.com/topic/251556-inner-join-display-info-on-the-web/#findComment-1290080 Share on other sites More sharing options...
jeff5656 Posted November 21, 2011 Share Posted November 21, 2011 Also put mysql_query($query) or die(mysql_error()); so the error will tell you what the problem is. Quote Link to comment https://forums.phpfreaks.com/topic/251556-inner-join-display-info-on-the-web/#findComment-1290082 Share on other sites More sharing options...
Pain Posted November 21, 2011 Author Share Posted November 21, 2011 Than you! That helped. Quote Link to comment https://forums.phpfreaks.com/topic/251556-inner-join-display-info-on-the-web/#findComment-1290099 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.