出现这种错误,建议检查
$result_news = $mysqli->query ( $query_news )
看这句代码执行后,得到的结果是否正确,即看 $result_news 是不是一个对象,可以用以下代码查看:
print_r($result_news)
正确的结果应该是类似下面的:
mysqli_result Object ( [current_field] =>0 [field_count] =>8 [lengths] =>[num_rows] =>1 [type] =>0 )
$result1->fetch_assoc()$mysqli = new mysqli("localhost", "my_user", "my_password", "world")
$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5"
if ($result = $mysqli->query($query)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"])
}
/* free result set */
$result->close()
}
---------------------------------------------------
原形 array mysqli_fetch_assoc ( mysqli_result result )
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world")
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error())
exit()
}
$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5"
if ($result = mysqli_query($link, $query)) {
/* fetch associative array */
while ($row = mysqli_fetch_assoc($result)) {
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"])
}
/* free result set */
mysqli_free_result($result)
}
/* close connection */
mysqli_close($link)
?>
你别混用阿,而且原形就一个参数,你给了俩
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)