jtakkinen_82 Posted March 30, 2008 Share Posted March 30, 2008 Hi, so now I have 2 tables, admin and users with the following fields: Admin ------- AdminID name password email level Users ------- ID name password email level And what I'd need to do is search the both tables for the correct username and password on my login.php -page in one mysql_query. Is it possible? It doesn't need to detect if the logged user is admin or not, I'll do it differently. I'd only need to be able to check the both tables at the same time... it's a long story. Quote Link to comment https://forums.phpfreaks.com/topic/98598-select-from-2-tables-simultaneously/ Share on other sites More sharing options...
fenway Posted March 30, 2008 Share Posted March 30, 2008 You could search with a UNION... you'll just have to alias the first column name. Quote Link to comment https://forums.phpfreaks.com/topic/98598-select-from-2-tables-simultaneously/#findComment-504663 Share on other sites More sharing options...
jtakkinen_82 Posted March 30, 2008 Author Share Posted March 30, 2008 You could search with a UNION... you'll just have to alias the first column name. What do you mean man? How does it work? Do you mean like this? SELECT admin.adminID, admin.username FROM admin UNION SELECT users.ID, users.username FROM users Quote Link to comment https://forums.phpfreaks.com/topic/98598-select-from-2-tables-simultaneously/#findComment-504728 Share on other sites More sharing options...
mwasif Posted March 30, 2008 Share Posted March 30, 2008 What do you mean man? How does it work? Do you mean like this? SELECT admin.adminID, admin.username FROM admin UNION SELECT users.ID, users.username FROM users Yes Quote Link to comment https://forums.phpfreaks.com/topic/98598-select-from-2-tables-simultaneously/#findComment-504742 Share on other sites More sharing options...
jtakkinen_82 Posted March 30, 2008 Author Share Posted March 30, 2008 Got it working perfecto, thanks again guys! Quote Link to comment https://forums.phpfreaks.com/topic/98598-select-from-2-tables-simultaneously/#findComment-504911 Share on other sites More sharing options...
aschk Posted March 31, 2008 Share Posted March 31, 2008 Curiously, this seems rather unnormalised to me, shouldn't "admin" be a level? Quote Link to comment https://forums.phpfreaks.com/topic/98598-select-from-2-tables-simultaneously/#findComment-505559 Share on other sites More sharing options...
jtakkinen_82 Posted March 31, 2008 Author Share Posted March 31, 2008 Curiously, this seems rather unnormalised to me, shouldn't "admin" be a level? Nope, I got "usrlevel" column on both admin and users tables, which determines the user level. Quote Link to comment https://forums.phpfreaks.com/topic/98598-select-from-2-tables-simultaneously/#findComment-505880 Share on other sites More sharing options...
aschk Posted April 1, 2008 Share Posted April 1, 2008 My point is that your data is not normalised, you have the SAME information split over 2 tables. If "admin" status is merely a flag, then ALL admins are users (which means they can go in the user table) and ALL users can have an "admin" column to denote whether they are admin's or not. That way you can still apply a "level" to each user, and some are flagged as admins. Seeing as they seem to share most of the same information anyway (email/username/password/id/level). I'm sure fenway would probably concur. *looks for fenway's input* Quote Link to comment https://forums.phpfreaks.com/topic/98598-select-from-2-tables-simultaneously/#findComment-506285 Share on other sites More sharing options...
jtakkinen_82 Posted April 1, 2008 Author Share Posted April 1, 2008 My point is that your data is not normalised, you have the SAME information split over 2 tables. If "admin" status is merely a flag, then ALL admins are users (which means they can go in the user table) and ALL users can have an "admin" column to denote whether they are admin's or not. That way you can still apply a "level" to each user, and some are flagged as admins. Seeing as they seem to share most of the same information anyway (email/username/password/id/level). I'm sure fenway would probably concur. *looks for fenway's input* Yeah you're right and I think I got it sorted now that I no longer have to "tie" the users onto teams with "teamID". I'm using the intermediate table now so it should be all cool... your suggested way was the way I had done it originally but I didn't want admins to be in a team and that was causing problems... Quote Link to comment https://forums.phpfreaks.com/topic/98598-select-from-2-tables-simultaneously/#findComment-506303 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.