• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Array in an array, I think

#7
[eluser]davidbehler[/eluser]
Try something like this:
Code:
function get_division($division = '')
{
    $this->db->select('first_name, last_name');
    $this->db->from('users');
    $this->db->like('division',$division.',');
    $this->db->or_like('division',','.$division.',');

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

    $temp = array();

    if($query->num_rows() > 0)
    {
        foreach($query->result_array() as $user)
        {
            $groups = explode(',', $user['division'];
            foreach($groups as $group)
            {
                if($group == $division)
                {
                    $temp[] = $user;
                }
            }
        }

        if(count($temp) > 0)
        {
            return $temp;
        }
        else
        {
            return FALSE;
        }
    }
    else
    {
        return FALSE;
    }
}
You might have to take into account that $division might be empty. With my solution that will return FALSE.

The better option would be to change your database layout, but as far as I understood that's not an option at all ^^

€dit:
Damn you verynewtothis, that's a nice one Smile


Messages In This Thread
Array in an array, I think - by El Forum - 08-10-2009, 08:46 PM
Array in an array, I think - by El Forum - 08-10-2009, 09:21 PM
Array in an array, I think - by El Forum - 08-10-2009, 09:35 PM
Array in an array, I think - by El Forum - 08-10-2009, 09:46 PM
Array in an array, I think - by El Forum - 08-11-2009, 12:31 AM
Array in an array, I think - by El Forum - 08-11-2009, 12:50 AM
Array in an array, I think - by El Forum - 08-11-2009, 01:16 AM
Array in an array, I think - by El Forum - 08-11-2009, 05:28 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.