我有一个用户表,其中用户当前已登录并且尚未上传照片(用户表中的图像列为空) 显示的图像为 Default.png。如果用户上传了图片,则显示该图像。
我的代码有什么问题吗?
这是我数据库中的表'user'(很抱歉,我无法在此处编写数据库结构)。
|编号 | gb_用户 | <强>= | 1 | me.jpg |
此 View (headers.php):
<?php $user_log = info_user_login();?>
<?php if(!empty($user_log->gb_user) == NULL):?>
<img class="img-circle" src="../assets/img/default.png" width="70" style="margin:20px 0 0 10px;">
<?php else:?>
<img class="img-circle" src="../assets/img/<?php echo $user_log('gb_user');?>" width="70" style="margin:20px 0 0 10px;">
<?php endif;?>
这个助手:
function info_user_login(){
$CI = & get_instance();
$CI->load->model('admin/setting_adm');
$get_data_login = $CI->setting_adm->get_data_log_user();
return $get_data_login;
}
这个模型:
function get_data_log_user(){
$id_login = $this->session->userdata('id');
$this->db->where('id', $id_login);
$this->db->from('user');
$q = $this->db->get();
return $q->result();
}
其中 ID = session_id_login
最佳答案
<?php if(!empty($user_log->gb_user) == NULL):?>
这个条件没有意义,empty() 将返回一个 bool 值。
尝试以下方法之一:
<?php if(empty($user_log->gb_user)):?>
<?php if($user_log->gb_user == NULL):?>
关于php - 当字段图像表为空时如何显示默认图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42294904/