webref.eu Posted June 6, 2009 Share Posted June 6, 2009 Hi All I have the following sql query: $sql = "SELECT ReviewId, UserId, ReviewRating, ReviewDesc, ReviewDate FROM Reviews WHERE ProductId LIKE $ProductId AND ReviewIsApproved=1 ORDER BY $sortby $sortdirection LIMIT $offset, $rowsperpage"; which I need to modify so that I can also retrieve the Username by linking the query to my Users table and using the UserId to retrieve the Username. So, how do I modify the query? I believe I need a join using the UserId as index, but I'm not sure of the syntax, please help. Rgds Link to comment https://forums.phpfreaks.com/topic/161178-solved-help-me-modify-this-mysql-query-please/ Share on other sites More sharing options...
webref.eu Posted June 6, 2009 Author Share Posted June 6, 2009 Here's the answer guys: $sql3 = "SELECT Reviews.ReviewId, Reviews.UserId, Reviews.ReviewRating, Reviews.ReviewDesc, Reviews.ReviewDate, Users.Username FROM Reviews LEFT JOIN Users ON Reviews.UserId = Users.UserId WHERE ProductId LIKE $ProductId AND ReviewIsApproved=1 ORDER BY $sortby $sortdirection LIMIT $offset, $rowsperpage"; Rgds Link to comment https://forums.phpfreaks.com/topic/161178-solved-help-me-modify-this-mysql-query-please/#findComment-850550 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.