Welcome Guest, Not a member yet? Register   Sign In
How NOT to use foreach when expecting only 1 record?
#1

[eluser]Slowcheetah[/eluser]
I'm wondering if and how it's possible to NOT use foreach when expecting only one record as a result.

My current model code:
Code:
function get_user_id($username, $useremail)
    {
        $this->db->where('username', $username);
        $this->db->where('email', $useremail);
        $query = $this->db->get('accounts', 1);
        if ($query->num_rows() == 1)
        {
            foreach ($query->result() as $row)
            {
                return $row->id;
            }
        }
    }


Messages In This Thread
How NOT to use foreach when expecting only 1 record? - by El Forum - 05-11-2009, 07:41 AM
How NOT to use foreach when expecting only 1 record? - by El Forum - 05-11-2009, 07:41 AM
How NOT to use foreach when expecting only 1 record? - by El Forum - 05-11-2009, 07:43 AM
How NOT to use foreach when expecting only 1 record? - by El Forum - 05-11-2009, 08:00 AM
How NOT to use foreach when expecting only 1 record? - by El Forum - 05-11-2009, 08:13 AM
How NOT to use foreach when expecting only 1 record? - by El Forum - 05-11-2009, 08:17 AM
How NOT to use foreach when expecting only 1 record? - by El Forum - 05-11-2009, 08:19 AM
How NOT to use foreach when expecting only 1 record? - by El Forum - 05-11-2009, 08:26 AM
How NOT to use foreach when expecting only 1 record? - by El Forum - 05-11-2009, 01:05 PM



Theme © iAndrew 2016 - Forum software by © MyBB