I am created a prepared select query and it appears the query is not picking up the DESC
or I have the bind_param
structured wrong. I am trying to get the last id
of the user_id's image to display. The user's image displays, but it is the first id image they have. I tried doing ASC
and it was the same thing.
Am I doing this right?
$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.'">';
}
I don't think you can :
You can use number instead of field name in the 'order by' clause