警告:mysqli_fetch_assoc()期望参数1为mysqli_result,字符串为

时间:2016-07-04 11:37:17

标签: php mysql sql mysqli

尝试获取表格中的最后一行,但抛出错误......

  

'警告:mysqli_fetch_assoc()期望参数1为   mysqli_result,'

中给出的字符串
$recents = "SELECT * FROM list ORDER BY id DESC LIMIT 1";
 Ah yes, forgot to execute query here
if ($result = mysqli_fetch_assoc($recents)) {
    $mName = $result['name'];
    $mDesc = $result['description'];
    $mCost = $result['cost'];
}

2 个答案:

答案 0 :(得分:2)

您需要传递查询结果,而不是查询字符串。

$sql = "SELECT * FROM list ORDER BY id DESC LIMIT 1";
$recent = mysqli_query($connetion, $sql);

答案 1 :(得分:1)

您忘记使用该语句来运行查询

$results=mysqli_query($conn,$recents)