简体   繁体   English

Codeigniter count_all_results然后获取返回错误号1066

[英]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_resultsmy_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.

相关问题 在CodeIgniter中验证count_all_results = 1 - Verify count_all_results = 1 in CodeIgniter Codeigniter 随 `count_all_results` 改变 - Codeigniter changes with `count_all_results` CodeIgniter中带有Active Record的“count_all_results”和“where”的问题 - problem with “count_all_results” and “where” with Active Record in CodeIgniter 如何在codeiginter中将count_all_results返回给ajax成功函数 - how to return count_all_results to ajax success function in codeiginter 使用查询中的count_all_results - use count_all_results from query 正确使用count_all_results()? - Appropriate use of count_all_results()? CodeIgniter 中的 $query>num_rows() 和 $this->db->count_all_results() 之间的区别 & 推荐哪一个 - difference between $query>num_rows() and $this->db->count_all_results() in CodeIgniter & which one is recommended 使用 $this->db->count_all_results() 时出错; 作为对布尔成员函数 num_rows() 的调用 - Error for using $this->db->count_all_results(); as Call to a member function num_rows() on boolean 错误号码:1066不唯一的表/别名:codeigniter中的'tb_perumahan' - Error Number: 1066 Not unique table/alias: 'tb_perumahan' in codeigniter 不唯一的表/别名:'siswa' 错误号:1066 Codeigniter - Not unique table/alias: 'siswa' Error Number: 1066 Codeigniter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM