Welcome Guest, Not a member yet? Register   Sign In
Selecting?
#4

[eluser]PhilTem[/eluser]
I prefer

Code:
function is_admin($username)
{
    return $this->db
                    ->from('users')
                    ->where('username', $username)
                    ->where('is_admin', '1')
                    ->count_all_results() == 1;

}

because it's much shorter (if you compress code) and you actually don't run a real select query but more a 'SELECT COUNT(*) FROM' query. Which is a little fail safer for sql-injections since it only returns a number and no full rows.

But both queries are right. I like mine just a little more since it only counts matches and doesn't select them Wink

Refer to CI user's guide -> database class -> active record.


Messages In This Thread
Selecting? - by El Forum - 02-02-2012, 08:14 AM
Selecting? - by El Forum - 02-02-2012, 08:19 AM
Selecting? - by El Forum - 02-02-2012, 08:22 AM
Selecting? - by El Forum - 02-02-2012, 08:35 AM
Selecting? - by El Forum - 02-02-2012, 08:42 AM
Selecting? - by El Forum - 02-02-2012, 08:54 AM
Selecting? - by El Forum - 02-02-2012, 10:15 AM
Selecting? - by El Forum - 02-02-2012, 10:25 AM
Selecting? - by El Forum - 02-02-2012, 10:26 AM
Selecting? - by El Forum - 02-02-2012, 10:58 AM
Selecting? - by El Forum - 02-02-2012, 11:04 AM
Selecting? - by El Forum - 02-02-2012, 12:10 PM



Theme © iAndrew 2016 - Forum software by © MyBB