如何选择vote_points最多的数据库记录并确保它最先显示? PHP/Kohana 3
大家好,像往常一样,感谢所有花时间阅读本文的人。
我正在尝试显示与已提出的问题相关的所有答案。我正在使用 Kohana 3。
到目前为止,我能够通过以下方式确定哪条记录具有最高的 vote_points:
$best_id = DB::query(Database::SELECT, 'SELECT id FROM answers WHERE vote_points=(SELECT MAX(vote_points) FROM answers) AND question_id ='.$question->id)->execute();
并且,我收集所有答案并通过将结果集放入 foreach 循环中来显示它们:
<?php foreach($question->answers->where('moderated', '=', 0)->where('deleted', '=', 0)->order_by('created_at', 'ASC')->find_all() as $answer): ?>
A bunch of display answer functions and divs~~~
我需要弄清楚一种确保带有 $best_id 的记录首先显示且仅显示一次的方法,而其余答案则按created_at asc 显示和排序。
谢谢大家!
Hello everyone and as usual, thank you to anyone taking the time to read this.
I am attempting to display all of the answers relevant to a question that has been asked. I am using Kohana 3.
So far, I am able to determine which record has the highest amount of vote_points via:
$best_id = DB::query(Database::SELECT, 'SELECT id FROM answers WHERE vote_points=(SELECT MAX(vote_points) FROM answers) AND question_id ='.$question->id)->execute();
And, I gather all of my answers and display them by placing the result set in a foreach loop:
<?php foreach($question->answers->where('moderated', '=', 0)->where('deleted', '=', 0)->order_by('created_at', 'ASC')->find_all() as $answer): ?>
A bunch of display answer functions and divs~~~
I need to figure out a way to ensure that the record with $best_id is displayed first, and only once, while the rest of the answers are displayed and ordered by created_at asc.
Thank you, everyone!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此查询应该执行所需的操作:
This query should do the needful:
我会这样写:(
仅当您想要特定数字时才限制 10)
然后您可以循环结果,将每个结果填充到一个数组中:
I would write that something like:
(limit 10 only if you want a specific number)
Then you can loop over the result, stuff each into an array: