Fairly simple array question

From: Date: Mon, 27 Oct 2003 04:24:58 +0000
Subject: Fairly simple array question
Groups: php.general 
Request: Send a blank email to php-general+get-167677@lists.php.net to get a copy of this message
I'm retrieving results from a MySQL database - they would be of the form (form table 'usergroup'): +----------+----------+ | username | group_id | +----------+----------+
| tparker  |        3 |
| tparker  |        6 |
| tparker  |        7 |
| tparker  |        8 |
+----------+----------+ This SQL query is being carried out within another function that does a query of the 'groups' table, and thus lists all groups. While listing all groups, I want to check wither the current item to be listed is equal to ANY of the group_id's in the result above (in other words, i'm presenting the user with a list of group checkboxes, but with those previously selected to be 'checked'). How is the best way to do this? By using mysql_fetch_assoc or object for the 'usergroup' table result, I have to check each item of the array for each item in the 'groups' list - very inefficient. How can I transfer the results above into an array such that I only need to check $group_result->group_id against $usergroup[$group_result->group_id] ? <-- I know that won't work syntactically, it's an example only. Or is there a better way of doing this? Is there a function that merely asks if an item (say, '6') exists in ALL the results above? Thanks in advance! Terence

« previous php.general (#167677) next »