Welcome Guest, Not a member yet? Register   Sign In
Output loop to string
#1

[eluser]codex[/eluser]
Ok guys,

this is probably a silly question, but I just can't see it (it's late and I had a bit of alcohol ;-) ).

I'm making a private messaging system and this part is where the new message is being inserted. See the loop below: $recipients is an array that holds the id's of the multiple receivers. What I want to do is take the array, query the db for the corresponding username, create a variable of the usernames and insert that together with the new message. The variable is just a simple string, example: 'jason, perry, luke, antoine'.

How do I write the loop to the variable?? Help is greatly appreciated!

Code:
foreach ($recipients as $recipient)
{
    $this->db->select('user_name');
    $this->db->where('user_id', $recipient);
    $query = $this->db->get('users');
    $user = $query->result_array();
            
    $str = $user[0]['user_name'] .', '; // this is obviously not the way to do it
}


Messages In This Thread
Output loop to string - by El Forum - 11-21-2008, 05:49 PM
Output loop to string - by El Forum - 11-21-2008, 05:55 PM
Output loop to string - by El Forum - 11-21-2008, 05:58 PM
Output loop to string - by El Forum - 11-21-2008, 06:04 PM



Theme © iAndrew 2016 - Forum software by © MyBB