问题
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