NathanLedet Posted July 15, 2008 Share Posted July 15, 2008 This code works, but it displays two of each database entry....I'm new with Joins, so i must be doing something wrong....clearly <table width="500px" border="1px"> <tr> <td width="25%">Name</td> <td width="50%">E-mail Address</td> <td width="15%">Options</td> </tr> </table> <div style="width:500px; overflow:auto;"> <table width="500px" border="0" id="addressbook"> <?php $query = "SELECT * FROM users, addressbook WHERE addressbook.userID = 2"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ echo "<tr>\n"; echo "<td width=\"25%\" class=\"tbldata\">" . $row['name'] . "</td>\n"; echo "<td width=\"60%\" class=\"tbldata\">" . $row['email'] . "</td>\n"; echo "<td width=\"15%\" class=\"tbldata\">edit/delete</td>\n"; echo "</tr>\n"; } ?> </table> </div> Oh and a little about my table structure: table: users userID username password email table: addressbook userID emailID name email The table 'users' is a list of people allowed to access the site. the table 'addressbook' is each 'users' personal e-mail addressbook. I am trying to join them together through the userID. the userID inside 'users' is unique and the userID inside 'addressbook' belongs to whichever 'user' added them to the database. Quote Link to comment Share on other sites More sharing options...
Barand Posted July 15, 2008 Share Posted July 15, 2008 You are not specifying the join condition $query = "SELECT * FROM users, addressbook WHERE users.userID = addressbook.userID AND addressbook.userID = 2"; or, better $query = "SELECT * FROM users JOIN addressbook ON users.userID = addressbook.userID WHERE addressbook.userID = 2"; Quote Link to comment Share on other sites More sharing options...
NathanLedet Posted July 15, 2008 Author Share Posted July 15, 2008 Awesome those work!!! THANKS I even managed to re-work it so that it uses Session data $query = "SELECT * FROM users JOIN addressbook ON users.userID = addressbook.userID WHERE users.username = '" . $_SESSION['MM_Username'] . "'"; I appreciate your help! 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.