简体   繁体   English

是否可以重新使用 Kohana ORM 查询来查询行数?

[英]Is it possible to re-use a Kohana ORM query for the row count?

So I have my query as so...所以我有我的疑问......

$records = ORM::factory('category');

Add a WHERE clause as so...像这样添加一个 WHERE 子句...

$records = $records->where('categoryid', 'LIKE', 'aa');

Grab a count for pagination as so...抓住分页计数,这样......

$count = $records->count_all();

And my where clause gets cleared away as so...我的where子句被清除了......

SELECT `categories`.* FROM `categories` LIMIT 20 OFFSET 0

With this line commented out将此行注释掉

//$count = $records->count_all();

My SQL looks just fine...我的 SQL 看起来还不错……

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...一个用于计数,一个用于实际结果...

Thanks!谢谢!

Use special reset(FALSE) call:使用特殊reset(FALSE)调用:

$records = $records->where('categoryid', 'LIKE', 'aa');
$records->reset(FALSE); // !!!!
$count = $records->count_all();
$categories = $records->find_all();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM