July 28, 201016 yr 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.
July 28, 201016 yr 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.
July 29, 201016 yr 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
July 29, 201016 yr 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".
July 29, 201016 yr 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... }
July 29, 201016 yr 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
Create an account or sign in to comment