gpt4 book ai didi

php - mysql FOUND_ROWS() 返回错误值

转载 作者:行者123 更新时间:2023-11-29 05:29:16 26 4
gpt4 key购买 nike

我尝试在查询中使用 FOUND_ROWS(),但该函数有时会返回错误的值。

SELECT SQL_CALC_FOUND_ROWS adminslog.*, admins.fullName FROM adminslog 
JOIN admins ON admins.id=adminslog.userId ORDER BY date DESC LIMIT 0,12

在这个查询中,我得到了一些正确的值,但在其他的限制中有错误的值。

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

这是我的类结构:

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...
}

最佳答案

一个 mysql 错误可能会导致此问题,具体取决于您使用的版本: http://bugs.mysql.com/bug.php?id=1468

您可以通过在查询中使用 GROUP BY 子句来解决此问题。

关于php - mysql FOUND_ROWS() 返回错误值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16477264/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com