imperium2335 Posted April 20, 2011 Share Posted April 20, 2011 Hi, I have a little script that shows a user or group of users' work based on branches and users. I.e, I would like all the users of a given branch to be able to see all the other users' things who are in the same branch only. But all I'm getting is far too many results (takes a long time to load!) not in any consistent format. I have tried using GROUP BY etc but with no luck, I just get different crazy results. $result = mysql_query("SELECT enquiries.*, users.* FROM enquiries, users WHERE enqState = 'New' AND users.branch = '$userBranch' AND enquiries.assignedToT = users.userName OR enqState = 'New' AND '$userLevel' > 4 ") ; Quote Link to comment https://forums.phpfreaks.com/topic/234218-drawing-from-multiple-tables-problem/ Share on other sites More sharing options...
Muddy_Funster Posted April 20, 2011 Share Posted April 20, 2011 Get rid of those SELECT * and explicitly name the fields that you want back. You don't use SELECT * like that anyway. Also, could you post your table strcture up, I'm pretty sure you should be using a JOIN in this. Quote Link to comment https://forums.phpfreaks.com/topic/234218-drawing-from-multiple-tables-problem/#findComment-1203873 Share on other sites More sharing options...
imperium2335 Posted April 20, 2011 Author Share Posted April 20, 2011 Thanks, I know I'm just being lazy , will optimise it once I have it working. users has this structure: id userName userPass branch Enquiries has: id detail_sheetRef assignedToT enqState I'm not to well versed on JOIN, how would that help in this case? Quote Link to comment https://forums.phpfreaks.com/topic/234218-drawing-from-multiple-tables-problem/#findComment-1203918 Share on other sites More sharing options...
Muddy_Funster Posted April 20, 2011 Share Posted April 20, 2011 ok, do the tables refference each other at all? and what field types are they all? Quote Link to comment https://forums.phpfreaks.com/topic/234218-drawing-from-multiple-tables-problem/#findComment-1203924 Share on other sites More sharing options...
imperium2335 Posted April 20, 2011 Author Share Posted April 20, 2011 enquiries.assignedToT references users.userName Quote Link to comment https://forums.phpfreaks.com/topic/234218-drawing-from-multiple-tables-problem/#findComment-1203939 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.