I'm trying to pull the total number of reviews for a product page template and for some reason I keep getting a result of one no matter what even though there's at least 2.
Can anyone help?
I have the following bits of code written.
$reviews_query_raw = "SELECT r.reviews_id, rd.reviews_text as reviews_text, r.reviews_rating, r.date_added, r.customers_name
FROM " . TABLE_REVIEWS . " r, " . TABLE_REVIEWS_DESCRIPTION . " rd
WHERE r.products_id = :productsID
AND r.reviews_id = rd.reviews_id
AND rd.languages_id = :languagesID " . $review_status . "
ORDER BY r.reviews_id desc";
$reviews_query_raw = $db->bindVars($reviews_query_raw, ':productsID', $_GET['products_id'], 'integer');
$reviews_query_raw = $db->bindVars($reviews_query_raw, ':languagesID', $_SESSION['languages_id'], 'integer');
$reviews_split = new splitPageResults($reviews_query_raw, MAX_DISPLAY_NEW_REVIEWS);
$reviews = $db->Execute($reviews_split->sql_query);
And then later in the page:
<?php echo $reviews->RecordCount(); ?>
And it's returning one. Even though I can run the same query in phpMyAdmin and get actual results.
You've set MAX_DISPLAY_NEW_REVIEWS to 1. splitPageResults class paginates Your original query, so transformed query has something like 'LIMIT 0, 1' at the end. To get total number of reviews use:
<?php echo $reviews_split->number_of_rows;?>
to know how many pages are required to display all reviews using current setting of MAX_DISPLAY_NEW_REVIEWS use:
<?php echo $reviews_split->number_of_pages;?>
You can change MAX_DISPLAY_NEW_REVIEWS in admin area in Configuration->Maximum/Minimum values
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.