sql query to get two differnt values of same columnsAsk Question


I am making an activity log for my website and to show the logs that user 1 followed user 2, I have their ids in my activity_log table. Now I want to retrieve their names from user_login table.

For example user_id=3;friend_id=6;. I want their username so that in activity log I can print "$user followed $friend". So I want to know about the query so that I can retrieve usernames using two variables, suppose variables are $finalres1=3;$finalres2=6; How do I fetch their usernames from table user_login with a single query

foreach($results as $res=>$finalres){



this query fetches me the username of user 1 but I need username of both the user and friend in single array.so in the view I can write them easily.


add that



add that $this->db->select('username as username1'); $this->db->from('user_login'); $this->db->where('id',$finalres1);

标签: mysql codeigniter rdbms codeigniter-3
© 2014 TuiCode, Inc.