if ($this->total_records==0 or !isset($this->total_records)){
if (empty($this->count_sql) and !empty($this->table["tablename"])){
$sql = "SELECT count(".$this->table["id"].") as count_id FROM `".$this->table["tablename"]."` ".($this->table["where"]!=""?" WHERE ".$this->table["where"]:"");
}else{
$sql = preg_replace("/SELECT(.*?)FROM(.*?)/i", "SELECT count(a.id) AS count_id FROM\\2", $this->sql);
}
$arr = $this->db->row_query_one($sql);
$this->total_records = $arr["count_id"];
}
}
复制代码
翻页后因为sql查询最后的limit 5,5而导致取不出总记录数
但取记录数用不的limit所以,可以把他用preg_replace去掉,得到:
//总记录数
function set_total_records(){
if ($this->total_records==0 or !isset($this->total_records)){
if (empty($this->count_sql) and !empty($this->table["tablename"])){
$sql = "SELECT count(".$this->table["id"].") as count_id FROM `".$this->table["tablename"]."` ".($this->table["where"]!=""?" WHERE ".$this->table["where"]:"");
}else{
$sql = preg_replace("/SELECT(.*?)FROM(.*?)/i", "SELECT count(a.id) AS count_id FROM\\2", $this->sql);