[英]Codeigniter count_all_results then get return error number 1066
I want to count all result by using $this->db->count_all_results()
in my query then get the query result ( $this->db->get
) without reset any field value. 我想通过在查询中使用$this->db->count_all_results()
来计数所有结果,然后获取查询结果( $this->db->get
),而无需重置任何字段值。 i have followed the user guide on Limiting or Counting Results it's say 我遵循了关于限制或计数结果的用户指南
However, this method also resets any field values that you may have passed to select(). 但是,此方法还会重置您可能传递给select()的任何字段值。 If you need to keep them, you can pass FALSE as the second parameter: 如果需要保留它们,可以将FALSE作为第二个参数传递:
i have passed FALSE parameter to the function but i get Database Error: 我已将FALSE参数传递给函数,但出现数据库错误:
Error Number: 1066 Not unique table/alias: 'my_table' 错误号:1066不是唯一的表/别名:'my_table'
this is the code i have tried 这是我尝试过的代码
$this->db->select('title', 'content', 'date');
$this->db->like('title', 'Post');
$this->db->order_by('title', 'DESC');
$records = $this->db->count_all_results('my_table', FALSE);
$query = $this->db->get('my_table', 20);
Thanks 谢谢
Why not just count the rows from the query resultset like so: 为什么不像这样只计算查询结果集中的行:
$this->db->select('title', 'content', 'date');
$this->db->like('title', 'Post');
$this->db->order_by('title', 'DESC');
$query = $this->db->get('my_table');
$records = $query->num_rows();
Hope this will help you : 希望这个能对您有所帮助 :
Make an alias of my_table
in count_all_results
like the below: 在count_all_results
为my_table
count_all_results
,如下所示:
$this->db->select('p.title, p.content, p.date');
$this->db->like('p.title', 'title');
$this->db->order_by('p.date', 'DESC');
$data['count'] = $this->db->count_all_results('my_table p', FALSE);
$data['records'] = $this->db->get('my_table')->result();
print_r($data);
for more : http://www.mysqltutorial.org/mysql-alias/ 有关更多信息: http : //www.mysqltutorial.org/mysql-alias/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.