完整错误消息:
Catchable fatal error: Object of class mysqli_result could not be converted to string in C:\wamp\www\profile_page.php on line 373
我在网站上实现无限滚动功能时遇到此错误。我不能(或者无法找到方法)实现mysqli_fetch_assoc
来获取结果,因为许多其他与此相关的答案都是如此。
以下是完整的代码,可以解释原因:
$limit = 10;
$page = (int) (!isset($_GET['p'])) ? 1 : $_GET['p'];
# sql query
$get_thoughts_from_db = mysqli_query($connect,
"SELECT * FROM user_thoughts WHERE added_by='$user' AND shared ='yes' ORDER BY id DESC");
# find out query start point
$start = ($page * $limit) - $limit;
# query for page navigation
if(mysqli_num_rows($get_thoughts_from_db) > ($page * $limit) ){
$next = ++$page;
}
$query = mysqli_query($connect, $get_thoughts_from_db . " LIMIT {$start}, {$limit}");
if (mysqli_num_rows($query) < 1) {
header('HTTP/1.0 404 Not Found');
echo 'Page not found!';
exit();
}
此行中出现错误(第373行):
$query = mysqli_query($connect, $get_thoughts_from_db . " LIMIT {$start}, {$limit}");
答案 0 :(得分:0)
您保存到$get_thoughts_from_db
mysqli_query结果:
$get_thoughts_from_db = mysqli_query($connect,
"SELECT * FROM user_thoughts WHERE added_by='$user' AND shared ='yes' ORDER BY id DESC");
然后用字符串连接它:
$query = mysqli_query($connect, $get_thoughts_from_db . " LIMIT {$start}, {$limit}");
也许您想要运行此查询:
$query = mysqli_query($connect,
"SELECT * FROM user_thoughts WHERE added_by='$user' AND shared ='yes' ".
"ORDER BY id DESC LIMIT {$start}, {$limit}");