ballhogjoni Posted July 27, 2007 Share Posted July 27, 2007 I am trying to JOIN two tables together using the common column "Username". My code is ECHOing all of rows of column "title". I want to just ECHO the column "title" rows that are specific to the "Username". example: I have a user named "ballhogjoni". This username is stored in a table named 'users' and in a table named 'products' under the column "Username". There is a "Username" column in each table. How do I get my code to echo the column I want? This is my code so far <?php $query = "SELECT title FROM users, products WHERE users.Username = products.Username"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['title']; echo "<br />"; } ?> Quote Link to comment Share on other sites More sharing options...
Fadion Posted July 27, 2007 Share Posted July 27, 2007 From mysql reference SELECT * FROM table1,table2 WHERE table1.id=table2.id; SELECT * FROM table1 LEFT JOIN table2 ON table1.id=table2.id; SELECT * FROM table1 LEFT JOIN table2 USING (id); 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.