Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, string given in

余生颓废 提交于 2020-02-26 04:32:06

问题


Trying to get the last row in the table but throwing error ...

'Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, string given in '

$recents = "SELECT * FROM list ORDER BY id DESC LIMIT 1";
if ($result = mysqli_fetch_assoc($recents)) {
    $mName = $result['name'];
    $mDesc = $result['description'];
    $mCost = $result['cost'];
}

回答1:


You need to pass a result from a query, not the query string.

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



回答2:


You forgot to use the statement to run the query

$results=mysqli_query($conn,$recents)


来源:https://stackoverflow.com/questions/38183792/warning-mysqli-fetch-assoc-expects-parameter-1-to-be-mysqli-result-string-gi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!