Jump to content

[SOLVED] Help Me Modify this MySQL Query Please


webref.eu

Recommended Posts

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

 

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.