php - mysql FOUND_ROWS() return wrong value -
i'm trying use found_rows() in query, function returns wrong values sometimes.
select sql_calc_found_rows adminslog.*, admins.fullname adminslog join admins on admins.id=adminslog.userid order date desc limit 0,12
in query, right value some, in others limit has wrong value.
limit 0,12 164rows right limit 12,12 164rows right limit 36,12 164rows right limit 48,12 164rows right limit 50,12 60rows wrong limit 62,12 60rows wrong
here class construct:
class list_table { public $number,$page_number,$all_rec,$table_rows,$query_str,$query,$fetch,$table,$db,$fields,$i=0,$page_n,$onclick; function __construct($query_str,$fields,$page_n,$onclick,$page_number,$number,$db) { $this->fields = $fields; $this->page_number = (((int)$page_number<1)?1:(int)$page_number); $this->number = (int)$number; $this->db = $db; $this->i = $this->page_number*$this->number-$this->number; $this->page_n = $page_n; $this->onclick = $onclick; $this->query_str = substr(trim($query_str),0,7)."sql_calc_found_rows ".substr(trim($query_str),7)." limit ".(($this->page_number*$this->number)-$this->number).",".$this->number; $this->query = $this->db->query($this->query_str); $this->table_rows = $this->db->query("select found_rows()")->fetchcolumn(); $this->all_rec = $this->query->rowcount(); $this->fetch = $this->query->fetch(); //$this->table_rows = $this->table_rows->fetch(); //$this->table_rows = $this->table_rows['cnt']; print $this->table_rows; } other functions... }
question: think first found_rows()
right every time in every query?
check that,if true can run code in first query , save session.
if($this->page_number==1) $_session['cr'] = $this->table_rows = $this->db->query("select found_rows()")->fetchcolumn();
in way have not check row counts every time.
Comments
Post a Comment