Jump to content

Recommended Posts

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";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/84923-working-with-mysql_fetch_array/
Share on other sites

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.

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. :)

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.