Forum Moderators: coopster

Message Too Old, No Replies

checklogin query

         

ScriptJnr

5:14 pm on Mar 26, 2008 (gmt 0)

10+ Year Member



Help.

My database has only one table for all the users userIDs of a system.

Whats the best way to write a MYSQL query that differentiates when an administator logs in/ and when a regular user logs in? (And maybe takes the user to a certain page depending on if they're Admin or not)

Must I create another table or something?

PHP_Chimp

5:20 pm on Mar 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That depends on the structure of the table you have.

If you have columns that are something like -
ID ¦ name ¦ password ¦ is_admin
then you can find if someone is an admin from that single table. I assume that you have something like that as otherwise you wouldnt know who was an admin.

"SELECT * FROM table WHERE is_admin = 1;" would give you a list of all admins.

You can then use


if ($result['is_admin']) {
// take them to admin page
}
else {
echo 'You are not an admin';
}

ScriptJnr

5:32 pm on Mar 26, 2008 (gmt 0)

10+ Year Member



Thanks, I'll work along that path.

What data type would you make "is_admin"? seeing as there's no boolean?

PHP_Chimp

9:19 pm on Mar 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you use 1 or 0 as the is_admin then you can use those as true and false for php.

So data type may as well be tinyint.

If you use sql bool then that will give you t or f, so you would then need to look for the string t or f when checking is_admin. So 0 or 1 will convert to false and true respectively from sql to php.