2016-05-13 70 views
-5
SELECT `users`.`first_name`, `user_profile`.`user_id`, 
`user_profile`.`image`, `messages`.* FROM `messages` LEFT JOIN `user_profile` ON 
`user_profile`.`user_id` = `messages`.`from_id` LEFT JOIN `users`ON `users`.`id` 
= `messages`.`from_id` WHERE (messages.delete_from != '9' AND messages.delete_to 
!='9’) AND (`messages`.`members` = '4,9' OR `messages`.`members` = '9,4') 
ORDER BY `date` ASC 
+1

阅读本https://www.codeigniter.com/userguide3/database/query_builder.html#selecting-data –

+4

停止懒惰,阅读活动记录手册并与之相关 – Ghost

+0

$ this-> db-> from($ this-> table); $ this-> db-> select('users.first_name,user_profile.user_id,user_profile.image,messages。*'); $ this-> db-> join('user_profile','user_profile.user_id = messages.from_id','left'); $ this-> db-> join('users','users.id = messages.from_id','left'); $ this-> db-> where($ id1); $ this-> db-> where($ id2); $ this-> db-> where('messages.members',$ con1); $ this-> db-> or_where('messages.members',$ con2);我用这个,但它不工作 – Anju

回答

0
$this->db->from($this->table); 
$this->db->select('users.first_name,user_profile.user_id,user_profile.image,messages.*'); 
$this->db->join('user_profile', 'user_profile.user_id = messages.from_id','left'); 
$this->db->join('users', 'users.id = messages.from_id','left'); 
$this->db->where($id1); 
$this->db->where($id2); 
$this->db->group_start(); 
$this->db->where('messages.members',$con1); 
$this->db->or_where('messages.members',$con2); 
$this->db->group_end(); 
$this->db->order_by('date','asc'); 

使用$this->db->group_start();$this->db->group_end();的括号

相关问题