Reputation: 45
I was using the fetch_object function to retrieve rows from my table when it stopped working after I tried retrieving the avatar column.
include "db_conx.php";
$sql = ('SELECT uid,username,avatar,country FROM users ORDER BY uid DESC LIMIT 10');
$result = mysqli_query($db_conx, $sql);
while($var = $result->fetch_object()->avatar){
echo $var; echo "<br />";
}
Instead of returning the avatar, it returns blank instead. I thought it would at least display the directories I had for the avatars, so I'm quite perplexed. All the other columns I selected work fine though.
Upvotes: 1
Views: 30
Reputation: 72299
You need to do in below ways:-
while($var = $result->fetch_object()){ // check change
echo $var->avatar; echo "<br />"; // check change
}
Or
while($obj = $result->fetch_assoc()){ // use assoc
echo $var['avatar']; echo "<br />";
}
Upvotes: 0
Reputation: 777
Try some thing like this
while($obj = $result->fetch_object()){
$var = $obj->avatar;
echo $var; echo "<br />";
}
Upvotes: 1