我有以下查询:
// pagination
if ($stmt = $mysqli->prepare('SELECT COUNT(id) FROM ' . $table)) {
$stmt->execute();
$stmt->bind_result($totalitems);
$stmt->fetch();
if (!isset($page)) {
$page = (int)$page_number <= 0 ? 1 : (int)$page_number;
}
$limit = 4;
if ($page > ceil($totalitems / $limit)) {
$page = ceil($totalitems / $limit);
}
$start = ($page - 1) * $limit;
$stmt->close();
if ($stmt2 = $mysqli->prepare(' SELECT t1.id, t2.*
FROM ' . $table . ' t1
INNER JOIN ' . $table2 . ' t2 ON t2.id = t1.id
' . $optional_cond . $optional_cond2 . '
LIMIT ?, ?')) {
$stmt2->bind_param('ii', $start, $limit);
$stmt2->execute();
$stmt2->bind_result($col1, $col2, etc...);
while ($row = $stmt2->fetch()) {
echo $col1 . '<br>';
}
} else echo "Statement failed: " . $mysqli->error . "<br>";
}
它无效,所以我添加了else
:
else echo "Statement failed: " . $stmt2->error . "<br>";
但它发出以下通知:
Notice: Trying to get property of non-object
我无法查看我的查询有什么问题,发生了什么?
FIX(由@Michael Berkowski撰写 - 评论中):
else echo "Statement failed: " . $mysqli->error . "<br>";