drummer101 Posted January 7, 2008 Share Posted January 7, 2008 In my database, I have people organized by user_id and each user_id is assigned to at minimum 2 group_id 's The problem I'm running into is that mysql_fetch_array() stops after the first returned result. <?php $user_id = mysql_query("SELECT phpbb_user_group.group_id FROM phpbb_user_group WHERE phpbb_user_group.user_id = '".$i['user_id']."' ORDER BY phpbb_user_group.group_id DESC"); ?> Assume $i['user_id'] == 2 Result would be: group_id 19 6 2 Now assume $i['user_id'] == 6 Result: group_id 11 6 How would I get my query to search ALL results and return true if any of the results met the case check? Case check: <?php if($i['group_id'] == 6){ //code } elseif($i['group_id'] == 19){ //code } else { echo "Not authorized"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84923-working-with-mysql_fetch_array/ Share on other sites More sharing options...
trq Posted January 7, 2008 Share Posted January 7, 2008 Your question is pretty unclear. Your only selecting the group_id with your query so the results you posted will never be returned. mysql_fetch_assoc() only returns one row each time it is called per result resource. You will need to call mysql_fetch_array within a loop to get all rows contained in the result. Quote Link to comment https://forums.phpfreaks.com/topic/84923-working-with-mysql_fetch_array/#findComment-432998 Share on other sites More sharing options...
drummer101 Posted January 7, 2008 Author Share Posted January 7, 2008 Are mysql_fetch_array and mysql_fetch_assoc identical? Quote Link to comment https://forums.phpfreaks.com/topic/84923-working-with-mysql_fetch_array/#findComment-433002 Share on other sites More sharing options...
simcoweb Posted January 7, 2008 Share Posted January 7, 2008 If you want all users from that table your query should be: "SELECT * FROM table_name WHERE clauses go here" Quote Link to comment https://forums.phpfreaks.com/topic/84923-working-with-mysql_fetch_array/#findComment-433004 Share on other sites More sharing options...
drummer101 Posted January 7, 2008 Author Share Posted January 7, 2008 If you want all users from that table your query should be: "SELECT * FROM table_name WHERE clauses go here" Don't need to select all users, just need to select the user thats logging in and check to see if they are a member of group X or group Y. Quote Link to comment https://forums.phpfreaks.com/topic/84923-working-with-mysql_fetch_array/#findComment-433008 Share on other sites More sharing options...
trq Posted January 7, 2008 Share Posted January 7, 2008 Are mysql_fetch_array and mysql_fetch_assoc identical? No. mysql_fetch_array returns an numerically indexed array as well as an associative. mysql_fetch_assoc, just the latter. Quote Link to comment https://forums.phpfreaks.com/topic/84923-working-with-mysql_fetch_array/#findComment-433009 Share on other sites More sharing options...
trq Posted January 7, 2008 Share Posted January 7, 2008 If you want all users from that table your query should be: "SELECT * FROM table_name WHERE clauses go here" Don't need to select all users, just need to select the user thats logging in and check to see if they are a member of group X or group Y. Then you need to do this in your query. Something like. SELECT user FROM table WHERE id = '$user' AND group_id = 1 OR group_id = 2; If that returns a row your users belongs to either group 1 or 2. Quote Link to comment https://forums.phpfreaks.com/topic/84923-working-with-mysql_fetch_array/#findComment-433013 Share on other sites More sharing options...
Ken2k7 Posted January 7, 2008 Share Posted January 7, 2008 <?php // is the variable $i defined ? // $user_id = mysql_query("SELECT group_id FROM phpbb_user_group WHERE group_id = '".$i['user_id']."'"); echo mysql_num_rows($user_id) > 0; ?> It'll return true if the user_id is in the database or false if not. Quote Link to comment https://forums.phpfreaks.com/topic/84923-working-with-mysql_fetch_array/#findComment-433016 Share on other sites More sharing options...
simcoweb Posted January 7, 2008 Share Posted January 7, 2008 I guess this statement threw me off. 'ALL' to me is more than one. How would I get my query to search ALL results and return true if any of the results met the case check? Quote Link to comment https://forums.phpfreaks.com/topic/84923-working-with-mysql_fetch_array/#findComment-433017 Share on other sites More sharing options...
drummer101 Posted January 8, 2008 Author Share Posted January 8, 2008 I guess this statement threw me off. 'ALL' to me is more than one. How would I get my query to search ALL results and return true if any of the results met the case check? Ah sorry for the confusion, I was referencing group_id 19 6 2 all of ^ THOSE ^ results, not all as in SELECT * , so I could check if any of the groups the member belongs to is one or another. But thorpe answered that. Quote Link to comment https://forums.phpfreaks.com/topic/84923-working-with-mysql_fetch_array/#findComment-433349 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.