计算给定产品的评论总数

发布于 2025-01-04 09:24:08 字数 1079 浏览 0 评论 0原文

我正在尝试提取产品页面模板的评论总数,但由于某种原因,尽管至少有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

君勿笑 2025-01-11 09:24:08

您已将 MAX_DISPLAY_NEW_REVIEWS 设置为 1。 splitPageResults 类对您的原始查询进行分页,因此转换后的查询末尾有类似“LIMIT 0, 1”的内容。要获取评论总数,请使用:

<?php echo $reviews_split->number_of_rows;?>

要了解使用 MAX_DISPLAY_NEW_REVIEWS 的当前设置显示所有评论需要多少页,请使用:

<?php echo $reviews_split->number_of_pages;?>

您可以在管理区域的配置 -> 最大值/最小值中更改 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:

<?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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文