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

[eluser]codex[/eluser]
[quote author="Armchair Samurai" date="1227333500"]Do one DB query to get the names, then do the loop rather than hitting up the DB multiple times. For example, something like:
Code:
$this->db->select('user_name');
$this->db->where_in('user_id', $recipients);
$query = $this->db->get('users');
$result = $query->result();

foreach ($result as $val)
    $arr[] = $val->user_name;

$str = implode(', ', $arr);
[/quote]

Thanks armchair!

I haven't used where_in before. Guess it's time to delve deeper into mysql/queries since the way I have been doing it (hitting the db multiple times) seems to be rather inefficient.

And of course! Implode()!! Jeez...


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