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 ") ; 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. 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? 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? 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 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
Archived
This topic is now archived and is closed to further replies.