Условный запрос группируется по - PullRequest
0 голосов
/ 22 мая 2018

Я пытаюсь получить группу данных по. И удалить нулевое значение и заменить пустым.Но это показывает одно значение.этот запрос работает, но показывает значение результата один и его значение не удаляется из результата.где значение равно нулю, то я хочу показать пустым.

 $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;
    }


  }

1 Ответ

0 голосов
/ 22 мая 2018
$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;
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...