HDFilmMaker2112 Posted June 7, 2011 Share Posted June 7, 2011 The below should be getting information from $tbl_name3 to ORDER the information gotten from $tbl_name. $tbl_name is the products table. $tbl_name3 is the reviews table. I need to get the review_product_rating from the reviews table and order the products by the review_product_rating. $sql30 = "SELECT * FROM $tbl_name JOIN $tbl_name3 USING(product_id) WHERE product_category='$cat' ORDER BY $sort_by_selected2 LIMIT $start, $limit"; $result30 = mysql_query($sql30) or die("Problem with the query: $sql30<br />" . mysql_error()); That code is returning no results, but the query itself isn't throwing any errors. EDIT: something else I just remembered is, the review_product_rating stored in the DB is for each individual review, so I will need to also AVG the review_product_rating results for each products. Link to comment https://forums.phpfreaks.com/topic/238620-issue-with-table-join-query/ Share on other sites More sharing options...
HDFilmMaker2112 Posted June 7, 2011 Author Share Posted June 7, 2011 Well I narrowed down the problem to being that there are no reviews in the reviews table. So I did this: if($_GET['sort_by']=="rating_lh" || $_GET['sort_by']=="rating_hl"){ $sql30 = "SELECT * FROM $tbl_name JOIN $tbl_name3 USING(product_id) WHERE product_category='$cat' ORDER BY $sort_by_selected2 LIMIT $start, $limit"; $result30 = mysql_query($sql30) or die("Problem with the query: $sql30<br />" . mysql_error()); if(mysql_num_rows($result30)==0){ $sort_by_selected2="product_id"; $sql30 = "SELECT * FROM $tbl_name WHERE product_category='$cat' ORDER BY $sort_by_selected2 LIMIT $start, $limit"; $result30 = mysql_query($sql30) or die("Problem with the query: $sql30<br />" . mysql_error()); } } else{ $sql30 = "SELECT * FROM $tbl_name WHERE product_category='$cat' ORDER BY $sort_by_selected2 LIMIT $start, $limit"; $result30 = mysql_query($sql30) or die("Problem with the query: $sql30<br />" . mysql_error()); } It's only returning the one product with the review though... I want the products that don't have a review to be listed after the first one. I guess the best work around is to generate a blank review, when ever a new product is entered into the system. Link to comment https://forums.phpfreaks.com/topic/238620-issue-with-table-join-query/#findComment-1226485 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.