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