我正在尝试获取数据组by.and删除空值并替换空白。 但它显示出一个价值。此查询有效,但显示结果值为1,并且不会从结果中删除值。其中value为null然后我想显示空白。
$userchat= $this->db->dbprefix('usres_chat');
$users = $this->db->dbprefix('users');
$this->db->select($userchat.'.chat_to,'.$userchat.'.chat_from,'.$userchat.'.message,'.$userchat.'.created_date,'.$users.'.name,'.$users.'.id as userId,'.$users.'.email,'.$users.'.image,'.$users.'.phone,'.$users.'.country,'.$users.'.company,');
$this->db->group_by('chat_from');
$this->db->where($userchat.'.chat_from!=1');
$this->db->from($userchat);
$this->db->join($users,$users.'.id='.$userchat.'.chat_from');
//$this->db->order_by($userchat.'.created_date','DESC');
//$this->db->limit($limit,0);
$query1 = $this->db->get();
$usersInfo = $query1->result_array();
//$sql = $this->db->last_query();
if(!empty($usersInfo)){
foreach ($usersInfo as $key=> $users){
$userId = $users['userId'];
$phone=$users['phone'];
$userImage = site_url('assets/profile_image/user_icon.png');
$image = $users['image'];
if($image != '' && file_exists(DocumentRoot.'assets/profile_image/'.$image)){
$userImage = site_url('assets/profile_image/'.$image);
}
$usersInfo[$key]['image'] = $userImage;
return $usersInfo;
}
}
答案 0 :(得分:1)
$userchat= $this->db->dbprefix('usres_chat');
$users = $this->db->dbprefix('users');
$this->db->select('IFNULL('.$userchat.'.chat_to,"") as chat_to,IFNULL('.$userchat.'.chat_from,"") as chat_from,IFNULL('.$userchat.'.message,"") as message,IFNULL('.$userchat.'.created_date,"") as created_date,IFNULL('.$users.'.name,"") as name ,IFNULL('.$users.'.id,"") as userId ,IFNULL('.$users.'.email,"") as email ,IFNULL('.$users.'.image,"") as image ,IFNULL('.$users.'.phone,"") as phone ,IFNULL('.$users.'.country,"") as country,IFNULL('.$users.'.company,"") as company');
$this->db->group_by('chat_from');
$this->db->where($userchat.'.chat_from!=1');
$this->db->from($userchat);
$this->db->join($users,$users.'.id='.$userchat.'.chat_from');
//$this->db->order_by($userchat.'.created_date','DESC');
//$this->db->limit($limit,0);
$query1 = $this->db->get();
$usersInfo = $query1->result_array();
//$sql = $this->db->last_query();
if(!empty($usersInfo)){
foreach ($usersInfo as $key=> $users){
$userId = $users['userId'];
$phone=$users['phone'];
$userImage = site_url('assets/profile_image/user_icon.png');
$image = $users['image'];
if($image != '' && file_exists(DocumentRoot.'assets/profile_image/'.$image)){
$userImage = site_url('assets/profile_image/'.$image);
}
$usersInfo[$key]['image'] = $userImage;
return $usersInfo;
}