Kaptain.
Telegram /
LinkedIn /
Email /
GIT /
RSS /
GPG /
Заказ печатных плат

№ 1754 В разделе
Programming
от November 24th, 2009,
В подшивках: CodeIgniter, PHP
CodeIgniter and SQL_CALC_FOUND_ROWS problem solved! I patched DB_active_rec.php today. Now I have ability to use SQL_CALC_FOUND_ROWS in my programs. If you use pages on your site, this function realy speed up it. With db->count_all* you send two big queries to DB, but with SQL_CALC_FOUND_ROWS solution you send only one big and one tiny.
$CI =& get_instance();
$CI->db->select('title, body');
$CI->db->SQL_CALC_FOUND_ROWS();
$CI->db->from('posts');
$query = $CI->db->get();
//All done, we got result. Now getting rows count
$count = $CI->db->query('SELECT FOUND_ROWS() as rowcount');
$count = $count->result();
patched_DB_active_rec.php.tar.bz
Fortune cookie: An Italian is COMBING his hair in suburban DES MOINES!
hey. i’m trying to download the patch from this page but the link seems to be down: http://blindage.org/?p=1754
is there anywhere else i could get it? thanks! 😀
try again
Great patch but I modified it a little bit to save ‘DISTINCT’ feature. Line 1502 should be changed from:
$sql = ( ! $this->ar_distinct) ? ‘SELECT ‘ : ‘SELECT DISTINCT ‘;
$sql = ( ! $this->ar_SQL_CALC_FOUND_ROWS) ? ‘SELECT ‘ : ‘SELECT SQL_CALC_FOUND_ROWS ‘;
to:
$sql = ( ! $this->ar_SQL_CALC_FOUND_ROWS) ? ‘SELECT ‘ : ‘SELECT SQL_CALC_FOUND_ROWS ‘;
$sql .= ( ! $this->ar_distinct) ? ” : ‘DISTINCT ‘;