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 />"; } ?> Link to comment https://forums.phpfreaks.com/topic/62048-mysql-join-syntax/ 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); Link to comment https://forums.phpfreaks.com/topic/62048-mysql-join-syntax/#findComment-308925 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.