CodeIgniter数据库查询限制 [英] CodeIgniter Database query limit
问题描述
我使用ActiveRecord做一些数据库查询,我需要分页结果,所以我做一个
$ this- > db-> limit($ pPagination ['Start'],$ pPagination ['Length']);
但我没有得到任何结果。使用 $ this-> db-> last_query();
似乎CodeIgniter生成以下SQL
SELECT *
FROM(`viw_contacts`)
WHERE`user_id`='1'
ORDER BY`contact_name'asc
LIMIT 0 OFFSET 15
当我在PHPMyAdmin中运行它时,它也返回0行。
但如果我修改它运行:
SELECT *
FROM(`viw_contacts` )
WHERE`user_id` ='1'
ORDER BY`contact_name'asc
LIMIT 0,15
然后我得到正确的结果。任何ideea为什么CodeIgniter生成这个SQL,为什么它不工作?
我使用CodeIgniter 1.7.3和MySQL 5.1.41
这是
$ this-> db-> limit($ pPagination ['Length'],$ pPagination ['Start']);
而不是
$ this-> db-> limit($ pPagination ['Start'],$ pPagination ['Length']);
第一个参数是长度,第二个是偏移量,而不是我的想法。 / p>
I'm doing some db querys using ActiveRecord and i need to paginate the results so i do a
$this->db->limit($pPagination['Start'], $pPagination['Length']);
but i don't get any results. Using $this->db->last_query();
it seems that CodeIgniter produces the following SQL
SELECT *
FROM (`viw_contacts`)
WHERE `user_id` = '1'
ORDER BY `contact_name` asc
LIMIT 0 OFFSET 15
which when i run it inside PHPMyAdmin also returns 0 rows.
But if i modify it an run :
SELECT *
FROM (`viw_contacts`)
WHERE `user_id` = '1'
ORDER BY `contact_name` asc
LIMIT 0, 15
Then i get the correct results. Any ideea why CodeIgniter generates this SQL and why it doesn't work?
I use CodeIgniter 1.7.3 and MySQL 5.1.41
Ok, found the issue.
It's
$this->db->limit($pPagination['Length'], $pPagination['Start']);
instead of
$this->db->limit($pPagination['Start'], $pPagination['Length']);
First param is the Length and second is the offset, not the other way around as i thought.
这篇关于CodeIgniter数据库查询限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!