Forum Moderators: coopster
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?
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';
}
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.