Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Need help with SQL Query to find product review

Featured Replies

I have oscommerce based shopping website.

 

I am trying to put the reviews tab in the product description page.

 

I have managed to show the reviews in the separate "reviews tab" but the problem is that unique reviews of that displayed product is not shown instead the last review in the database is shown on every single product's page.

 

Seems like the SQL query is not finding the review of specific product.

 

The SQL queries that I am suing are below.

 

// find reviews
$reviews_query = tep_db_query("select count(*) as count from " . TABLE_REVIEWS . " where products_id = '" . (int)$product_info['products_id'] . "'");
   $reviews = tep_db_fetch_array($reviews_query); 


//find all the reviews 
 $reviews_query_raw = "select r.reviews_id, left(rd.reviews_text, 100) as reviews_text, r.reviews_rating, r.date_added, p.products_id, pd.products_name, p.products_image, r.customers_name from " . TABLE_REVIEWS . " r, " . TABLE_REVIEWS_DESCRIPTION . " rd, " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = r.products_id and r.reviews_id = rd.reviews_id and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and rd.languages_id = '" . (int)$languages_id . "' order by r.reviews_id DESC";
       $reviews_split = new splitPageResults($reviews_query_raw, MAX_DISPLAY_NEW_REVIEWS);
               $reviews_query = tep_db_query($reviews_split->sql_query); 
//display the reviews
       while ($reviews = tep_db_fetch_array($reviews_query)) {
                                               $reviews_customer_name=sprintf(TEXT_REVIEW_BY, tep_output_string_protected($reviews['customers_name'])) ;
                                               $reviews_date_added=sprintf(TEXT_REVIEW_DATE_ADDED, tep_date_long($reviews['date_added']));
                                               $reviews_rating=sprintf(TEXT_REVIEW_RATING, tep_image(DIR_WS_IMAGES . 'stars_' . $reviews['reviews_rating'] . '.gif', sprintf(TEXT_OF_5_STARS, $reviews['reviews_rating'])), sprintf(TEXT_OF_5_STARS, $reviews['reviews_rating'])) ;
                                               $reviews_text=stripslashes($reviews['reviews_text']) ;

                                               }    

											// add some definitions

$reviews_no=$reviews_split->number_of_rows;
$reviews_link=tep_href_link(FILENAME_PRODUCT_REVIEWS, tep_get_all_get_params() . $params) ;
$reviews_write_link=tep_href_link(FILENAME_PRODUCT_REVIEWS_WRITE, tep_get_all_get_params(array('reviews_id'))) ;

 

my website is www.thecheaplaptops.co.uk

 

the first query "$reviews_query" seems to be the one that needs to be changed. please advice. your help will be really appreciated.

surely you need to add where in p.product_id = (int)$product_info['products_id'] to your second query? There doesn't appear to be anything telling it which product to get reviews for.

  • Author

surely you need to add where in p.product_id = (int)$product_info['products_id'] to your second query? There doesn't appear to be anything telling it which product to get reviews for.

 

 

Hi thanks for your help so far, I tried inserting where p.product_id = (int)$product_info['products_id'] into second query but it is giving me errors. I am not good at MYSQL queries can you please tell me how it needs to be inserted.

 

Thanks

  • Author

Hi thanks for your help so far, I tried inserting where p.product_id = (int)$product_info['products_id'] into

 

Problem solved replaced the whole query with following and it is working now.

 

$reviews_query_raw = "select r.reviews_id, left(rd.reviews_text, 1000) as reviews_text, r.reviews_rating, r.date_added, r.customers_name from " . TABLE_REVIEWS . " r, " . TABLE_REVIEWS_DESCRIPTION . " rd where r.products_id = '" . (int)$product_info['products_id'] . "' and r.reviews_id = rd.reviews_id and rd.languages_id = '" . (int)$languages_id . "' order by r.date_added desc";

 

Thanks for your help. Just wanted to take it bit further and can you please tell me if you know how to write a statement saying if no reviews found then display "Be the first person to review this product".

Problem solved replaced the whole query with following and it is working now.

 

$reviews_query_raw = "select r.reviews_id, left(rd.reviews_text, 1000) as reviews_text, r.reviews_rating, r.date_added, r.customers_name from " . TABLE_REVIEWS . " r, " . TABLE_REVIEWS_DESCRIPTION . " rd where r.products_id = '" . (int)$product_info['products_id'] . "' and r.reviews_id = rd.reviews_id and rd.languages_id = '" . (int)$languages_id . "' order by r.date_added desc";

 

Thanks for your help. Just wanted to take it bit further and can you please tell me if you know how to write a statement saying if no reviews found then display "Be the first person to review this product".

 

 

if (mysql_num_rows(mysql_query($reviews_query_raw)) == "0"){
echo "Be the first to review this product!";
} else {
//List out reviews...
}

  • Author

if (mysql_num_rows(mysql_query($reviews_query_raw)) == "0"){
echo "Be the first to review this product!";
} else {
//List out reviews...
}

 

 

Thanks mate, got it working using the code given. Thanks

Thanks mate, got it working using the code given. Thanks

 

Glad it worked :D

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.