Php 获取返回空白而不是头像的对象?
我正在使用fetch_object函数从表中检索行,但在我尝试检索avatar列后,它停止了工作Php 获取返回空白而不是头像的对象?,php,mysql,mysqli,Php,Mysql,Mysqli,我正在使用fetch_object函数从表中检索行,但在我尝试检索avatar列后,它停止了工作 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){
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 />";
}
包括“db_conx.php”;
$sql=('selectuid,username,avatar,country fromsuserorderbyuiddesc LIMIT 10');
$result=mysqli\u查询($db\u conx,$sql);
而($var=$result->fetch_object()->avatar){
echo$var;echo“
”;
}
它不是返回化身,而是返回空白。我想它至少会显示我的头像目录,所以我很困惑。不过,我选择的所有其他专栏都很好 试试这样的东西
while($obj = $result->fetch_object()){
$var = $obj->avatar;
echo $var; echo "<br />";
}
while($obj=$result->fetch_object()){
$var=$obj->avatar;
echo$var;echo“
”;
}
您需要通过以下方式执行:-
while($var = $result->fetch_object()){ // check change
echo $var->avatar; echo "<br />"; // check change
}
while($var=$result->fetch_object()){//检查更改
echo$var->avatar;echo“
”;//检查更改
}
或
while($obj=$result->fetch_assoc()){//使用assoc
echo$var['avatar'];echo“
”;
}
谢谢您的评分。很高兴能帮助您。如果答案还没有完成,请投票表决
while($obj = $result->fetch_assoc()){ // use assoc
echo $var['avatar']; echo "<br />";
}