Warning: mysqli_fetch_assoc() expects parameter 1

2020-05-10 07:11发布

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'];
}

2条回答
小情绪 Triste *
2楼-- · 2020-05-10 07:17

You forgot to use the statement to run the query

$results=mysqli_query($conn,$recents)
查看更多
姐就是有狂的资本
3楼-- · 2020-05-10 07:25

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);
查看更多
登录 后发表回答