按时间顺序对评论列表进行排序

发布于 2024-07-10 01:35:27 字数 1229 浏览 5 评论 0原文

我正在尝试按时间顺序对电影评论列表进行排序。 我们有两个选项可供用户选择:按时间顺序排列和按字母顺序排列。 该页面默认按字母顺序排列,但是当人们单击按时间顺序排列的选项时,什么也没有发生。

这是我们现在拥有的代码:

// category 3 is 'reviews', category 12 is 'dvd reviews'
                if (($GLOBALS["CategoryId"] == 3 || $GLOBALS["CategoryId"] == 12) && !isset($_GET['unsort']))
                {
                    $output = AL_HELPER::GetArticles($articleResult);
                }
                else
                {
                    $output = AL_HELPER::GetArticlesABC($articleResult);
                }

我所做的是翻转两个 if。 将 GetArticles 放在第一位,然后将 GetArticlesABC 放在第二位 - 意味着它看起来像这样:

// category 3 is 'reviews', category 12 is 'dvd reviews'
                if (($GLOBALS["CategoryId"] == 3 || $GLOBALS["CategoryId"] == 12) && !isset($_GET['unsort']))
                {
                    $output = AL_HELPER::GetArticlesABC($articleResult);
                }
                else
                {
                    $output = AL_HELPER::GetArticles($articleResult);
                }

它确实按时间顺序对评论进行排序,但它取消了所有按字母顺序排列的选项。 本质上,这是一长串按时间顺序排列的评论。 显然这不是我们想要的。

有谁知道如何限制页面上列出的项目数量? 或者也许这里需要一种完全不同的方法,如果是这样,有什么建议吗?

I am trying to sort a list of movie reviews in chronological order. We have two options users can choose from, chronological and alphabetical. The page defaults to alphabetical, but when people click on the chronological option, nothing happens.

Here is the code we have right now:

// category 3 is 'reviews', category 12 is 'dvd reviews'
                if (($GLOBALS["CategoryId"] == 3 || $GLOBALS["CategoryId"] == 12) && !isset($_GET['unsort']))
                {
                    $output = AL_HELPER::GetArticles($articleResult);
                }
                else
                {
                    $output = AL_HELPER::GetArticlesABC($articleResult);
                }

What I did was flip-flop the two ifs. Putting GetArticles first and GetArticlesABC second- meaning it looked like this:

// category 3 is 'reviews', category 12 is 'dvd reviews'
                if (($GLOBALS["CategoryId"] == 3 || $GLOBALS["CategoryId"] == 12) && !isset($_GET['unsort']))
                {
                    $output = AL_HELPER::GetArticlesABC($articleResult);
                }
                else
                {
                    $output = AL_HELPER::GetArticles($articleResult);
                }

It did indeed sort the reviews chronologically but it took away all of the alphabetical options. Essentially it was a long list of chronological reviews. So obviously that's not what we want.

Does anyone know how to limit the number of items that it lists on the page? Or maybe a completely different approach is needed here, if so, any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

邮友 2024-07-17 01:35:31

如果使用后端数据库和 SQL,则限制每页结果的数量就像使用 LIMIT 运算符仅检索一组结果一样简单。 然后,您可以通过在页面之间传递与您提取的结果集相关的变量来实现下一个/上一个操作。

例如:

SELECT <Whatever> FROM <review table> LIMIT 0,10

将检索前 10 个结果。

SELECT <Whatever> FROM <review table> LIMIT 10,20

将检索下 10 个。通过用变量替换数字,您可以实现分页:

SELECT <Whatever> FROM <review table> LIMIT resultIndex,resultIndex+10

Limiting the number of results per page, if using a backend database and SQL is as simple as using the LIMIT operator to only retrieve a set number of results. You can then implement next/previous operations by passing a variable between pages which relates to the set of results you have pulled.

For example:

SELECT <Whatever> FROM <review table> LIMIT 0,10

Will retrieve the first 10 results.

SELECT <Whatever> FROM <review table> LIMIT 10,20

Will retrieve the next 10. By substituting the numbers with variables you can achieve pagination:

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