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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to