codeigniter の count_all_results() の問題

WBOY
リリース: 2016-08-08 09:26:50
オリジナル
2475 人が閲覧しました

SQL 句は次のとおりです:

$this->db->select('*')->from(スパン>'mytable'); $this->db->select('*')->from('mytable');

$count = $this->db->count_all_results() ;

$config = array(
'base_url' => '/financing/dayconsumption',
'total_items' => $count,
'current_page' => $page,
'items_per_page' => $this->pagesize,
);
$this->pagination2->init($config);
$this->db->limit($this->pagesize, $this->pagination2->sql_offset);
$query = $this->db->get();

。。。。。。

运行后报错:

A Database Error Occurred

Error Number: 1096

No tables used

SELECT * LIMIT 20

Line Number: 330

调试后发现问题出在:$count = $this->db->count_all_results() ;

$count = $this->db->count_all_results() ;


$config = array(

'base_url' => '/finding/dayconsumption',

'total_items' => $page,
'$this->pageサイズ、

);

$this->pagination2->init($config);
$this->db->limit($this->pagesize, $this->pagination2->sql_offset);

$query = $this->db->get();


。。。。。

実行後报错:

データベースエラーが発生しました

エラー番号: 1096テーブルが使用されていません SELECT * LIMIT 20Line Number: 330调试後発行现问题出在: $count = $this ->db->count_all_results() ;これは、次の count_all_results() のソースコード:
/** * "Count All Results" query * * Generates a platform-specific query string that counts all records * returned by an Active Record query. * * @param string * @return string */ public function count_all_results($table = '') { if ($table != '') { $this->_track_aliases($table); $this->from($table); } $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows')); $query = $this->query($sql); $this->_reset_select(); //注意这里 if ($query->num_rows() == 0) { return 0; } $row = $query->row(); return (int) $row->numrows; }
ログイン後にコピー
メソッド中调使用了_reset_select() メソッド、継続的に追跡_reset_select() メソッド:
/** * Resets the active record values. Called by the get() function * * @return void */ protected function _reset_select() { $ar_reset_items = array( 'ar_select' => array(), 'ar_from' => array(), 'ar_join' => array(), 'ar_where' => array(), 'ar_like' => array(), 'ar_groupby' => array(), 'ar_having' => array(), 'ar_orderby' => array(), 'ar_wherein' => array(), 'ar_aliased_tables' => array(), 'ar_no_escape' => array(), 'ar_distinct' => FALSE, 'ar_limit' => FALSE, 'ar_offset' => FALSE, 'ar_order' => FALSE, ); $this->_reset_run($ar_reset_items); }
ログイン後にコピー
それはここにあり、注釈を参照してください。確認のため、_reset_run() を追跡し続けると、_reset_select() の上に到達します:
/** * Resets the active record values. Called by the get() function * * @param array An array of fields to reset * @return void */ protected function _reset_run($ar_reset_items) { foreach ($ar_reset_items as $item => $default_value) { if ( ! in_array($item, $this->ar_store_array)) { $this->$item = $default_value; } } }
ログイン後にコピー
結果、アクティブ レコードが再配置されました。レコード再配置、後面の $query 获取不到データ了、解决办法:
$this->db->start_cache(); $this->db->select('*')->from('mytable'); $this->db->stop_cache(); ...... $query = $this->db->get(); $items = $query->result(); $this->db->flush_cache();
ログイン後にコピー
以上は、codeigniter の count_all_results() の問題を解決するもので、側面の内容が含まれており、PHP 教則に関心のある友人の助けになることを望みます。
関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!