是否可以将Kohana ORM查询重新用于行数? [英] Is it possible to re-use a Kohana ORM query for the row count?
本文介绍了是否可以将Kohana ORM查询重新用于行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有这样的查询...
So I have my query as so...
$records = ORM::factory('category');
这样添加WHERE子句...
Add a WHERE clause as so...
$records = $records->where('categoryid', 'LIKE', 'aa');
这样就可以分页了...
Grab a count for pagination as so...
$count = $records->count_all();
我的where子句也因此被清除了...
And my where clause gets cleared away as so...
SELECT `categories`.* FROM `categories` LIMIT 20 OFFSET 0
此行已被注释掉
//$count = $records->count_all();
我的SQL看起来很好...
My SQL looks just fine...
SELECT `categories`.* FROM `categories` WHERE `categoryid` LIKE 'aa' LIMIT 20 OFFSET 0
是否可以按我尝试的方式使用单个查询,还是必须进行两个重复的相同查询?一种是计数,一种是实际结果...
Is it possible to use a single query the way I'm trying to or do I have to make two duplicate identical queries? One for the count, and one for the actual results...
谢谢!
推荐答案
使用特殊的reset(FALSE)
调用:
$records = $records->where('categoryid', 'LIKE', 'aa');
$records->reset(FALSE); // !!!!
$count = $records->count_all();
$categories = $records->find_all();
这篇关于是否可以将Kohana ORM查询重新用于行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文