Jump to content

Select from 2 tables simultaneously?


jtakkinen_82

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/98598-select-from-2-tables-simultaneously/
Share on other sites

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

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*

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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.