计算给定产品的评论总数
我正在尝试提取产品页面模板的评论总数,但由于某种原因,尽管至少有 2 条评论,但无论如何我都会得到 1 条评论的结果。
任何人都可以帮忙吗?
我写了以下代码。
$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);
然后在页面后面:
<?php echo $reviews->RecordCount(); ?>
它正在返回一个。即使我可以在 phpMyAdmin 中运行相同的查询并获得实际结果。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已将 MAX_DISPLAY_NEW_REVIEWS 设置为 1。 splitPageResults 类对您的原始查询进行分页,因此转换后的查询末尾有类似“LIMIT 0, 1”的内容。要获取评论总数,请使用:
要了解使用 MAX_DISPLAY_NEW_REVIEWS 的当前设置显示所有评论需要多少页,请使用:
您可以在管理区域的配置 -> 最大值/最小值中更改 MAX_DISPLAY_NEW_REVIEWS
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:
to know how many pages are required to display all reviews using current setting of MAX_DISPLAY_NEW_REVIEWS use:
You can change MAX_DISPLAY_NEW_REVIEWS in admin area in Configuration->Maximum/Minimum values