acidglitter Posted January 30, 2008 Share Posted January 30, 2008 this is what i have $sql=mysql_query("SELECT members.*, categories.* FROM members INNER JOIN categories ON categories.id = {$_SESSION['id']} ORDER BY categories.category_order ASC, members.member_id ASC"); and for some reason its displaying each member once in every category instead of showing each member only once in the right category... does anyone see whats wrong with my code? Link to comment https://forums.phpfreaks.com/topic/88593-solved-weird-mysql-result/ Share on other sites More sharing options...
effigy Posted January 30, 2008 Share Posted January 30, 2008 You're not joining categories to members. Link to comment https://forums.phpfreaks.com/topic/88593-solved-weird-mysql-result/#findComment-453593 Share on other sites More sharing options...
acidglitter Posted January 30, 2008 Author Share Posted January 30, 2008 i don't think thats it i tried simplifying the code and making a temporary field with the same id that {$_SESSION['id']} had and joining it to that and its still messing up.. like i'm still just testing everything, so right now there are 2 members and 3 categories, and i tried doing mysql_num_rows on the query and its saying there are 6 members.... Link to comment https://forums.phpfreaks.com/topic/88593-solved-weird-mysql-result/#findComment-453601 Share on other sites More sharing options...
acidglitter Posted January 30, 2008 Author Share Posted January 30, 2008 this is the exact code i have right now... SELECT train_1.*, trains_categories.* FROM train_1 INNER JOIN trains_categories ON train_1.train_id = trains_categories.train_id trains_categories has all of the categories for all of the trains. train_1 has all of the members for just that train (just in case you didnt already figure that out ) Link to comment https://forums.phpfreaks.com/topic/88593-solved-weird-mysql-result/#findComment-453607 Share on other sites More sharing options...
acidglitter Posted January 30, 2008 Author Share Posted January 30, 2008 could i do this? INNER JOIN trains_categories ON train_1.train_id = trains_categories.train_id AND table.field = table.other_field can you put ANDs in inner joins? Link to comment https://forums.phpfreaks.com/topic/88593-solved-weird-mysql-result/#findComment-453663 Share on other sites More sharing options...
fenway Posted January 30, 2008 Share Posted January 30, 2008 Yup... I prefer to wrap the entire on clause in parens just to be explicit. Link to comment https://forums.phpfreaks.com/topic/88593-solved-weird-mysql-result/#findComment-453714 Share on other sites More sharing options...
acidglitter Posted January 30, 2008 Author Share Posted January 30, 2008 okay well i've figured out my problem. thanks for the help Link to comment https://forums.phpfreaks.com/topic/88593-solved-weird-mysql-result/#findComment-453911 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.