NationGamer Posted February 1, 2011 Posted February 1, 2011 im building a gang mail box and only want it to show to members within that gang ive join these table together but 1 problem is that it still shows to every member in game could someone please help thanks $q=$db->query("SELECT m.*,u.*,g.* FROM gang_mail m LEFT JOIN users u ON m.gangid=u.gang LEFT JOIN gangs g ON g.gangID=u.gang WHERE m.gangid=g.gangID ORDER BY time DESC LIMIT $page,1"); <--------------EDIT-------------> i think might have fixed it i used this sql instead $q=$db->query("SELECT m.*,u.*,g.* FROM gang_mail m LEFT JOIN users u ON u.userid='".$ir['userid']."' LEFT JOIN gangs g ON g.gangID=u.gang WHERE m.gangid=g.gangID ORDER BY time DESC LIMIT $page,10"); tell me fi you see any flaws in it thanks Quote
Diesl Posted February 1, 2011 Posted February 1, 2011 keep what you had originally, but your WHERE statement block should be WHERE m.gangid=g.gangID AND u.userid='".$ir['userid']."' your edited SQL code will not join your tables properly. Quote
SilvaTungDevil Posted February 1, 2011 Posted February 1, 2011 I see a massive flaw. $db->query("SELECT m.*,u.*,g.* FROM gang_mail m LEFT JOIN users u ON u.userid='".$ir['userid']."' LEFT JOIN gangs g ON g.gangID=u.gang WHERE m.gangid=g.gangID ORDER BY time DESC LIMIT $page,10"); Do you really need to select every column from the users table? Really every column? Like wise do you need every column from the gang table? I doubt it very much, try optimising your queries a bit ;) Quote
NationGamer Posted February 6, 2011 Author Posted February 6, 2011 thanks for you advice guys and silver ive edit sql now to only select what i actually need thanks Quote
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.