jimmyoneshot Posted August 8, 2011 Author Share Posted August 8, 2011 Yep I know but the problem is I'm not sure of any other way around it query wise without doing 1 complete mysql_query to get the logged in user's id and user_type and then doing another complete mysql_query to get the extra user details based on the user_type and user_if retrieved from the first query. Like you said I'm not sure it's possible to do what I'm after in 1 query Quote Link to comment https://forums.phpfreaks.com/topic/243946-if-statement-inside-query-based-on-other-tables-data/page/2/#findComment-1254246 Share on other sites More sharing options...
kickstart Posted August 8, 2011 Share Posted August 8, 2011 Hi Just use the syntax in my first post on this thread. SELECT * FROM users LEFT OUTER JOIN regular_user_details ON users.id = regular_user_details.userid LEFT OUTER JOIN business_user_details ON users.id = business_user_details.userid All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/243946-if-statement-inside-query-based-on-other-tables-data/page/2/#findComment-1254259 Share on other sites More sharing options...
jimmyoneshot Posted August 8, 2011 Author Share Posted August 8, 2011 Aha gotchya so it would only be the result that has empty/null fields not the database as obviously I would be doing this:- SELECT users.id, users.user_type, regular_user_details.name, regular_user_details.surname, regular_user_details.address, regular_user_details.age, business_user_details.company, business_user_details.contact, business_user_details.fax FROM users LEFT OUTER JOIN regular_user_details ON users.id = regular_user_details.userid LEFT OUTER JOIN business_user_details ON users.id = business_user_details.userid WHERE users.username = 'blah' AND users.password = 'blah' And then if I have any more user types I just join onto those tables too correct? Quote Link to comment https://forums.phpfreaks.com/topic/243946-if-statement-inside-query-based-on-other-tables-data/page/2/#findComment-1254268 Share on other sites More sharing options...
kickstart Posted August 8, 2011 Share Posted August 8, 2011 Hi Yes. If the returned row was for a business user then the columns from the regular user table would be null (and the same the other way round). All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/243946-if-statement-inside-query-based-on-other-tables-data/page/2/#findComment-1254273 Share on other sites More sharing options...
jimmyoneshot Posted August 8, 2011 Author Share Posted August 8, 2011 Sounds good. If all else fails join everything basically Thanks for all the help. Quote Link to comment https://forums.phpfreaks.com/topic/243946-if-statement-inside-query-based-on-other-tables-data/page/2/#findComment-1254276 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.