Jump to content

Recommended Posts

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.