Pau*_*aul 2 php mysql sql select prepared-statement
我创建了一个准备好的选择查询,看起来查询没有拿起DESC
或我有bind_param
结构错误.我id
想要显示最后一个user_id的图像.显示用户的图像,但它是他们拥有的第一个id图像.我试过了ASC
,这是同样的事情.
我这样做了吗?
$sql = "
SELECT *
FROM profile_img
WHERE user_id = ?
ORDER BY ? DESC LIMIT 1
";
if ($stmt = $con->prepare($sql)) {
$stmt->bind_param("ss", $user_id, `id`);
$stmt->execute();
if (!$stmt->errno) {
// Handle error here
}
$stmt->bind_result($id, $user_id, $profilePic);
$pics = array();
while ($stmt->fetch()) {
$pics[] = $profilePic;
}
echo '<img id="home-profile-pic" src=" '.$profilePic.'">';
}
Run Code Online (Sandbox Code Playgroud)
我认为你不能:
You can use number instead of field name in the 'order by' clause