简体   繁体   中英

sql query to get two differnt values of same columns

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){
    $finalres1=$finalres['user_id'];
    $finalres2=$finalres['friend_id'];

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

    $query=$this->db->get();
    $result3=$query->result_array();

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.

加上

$this->db->or_where('id',$finalres2)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM