I've got a brain-bender I'm wondering if anyone can help me clean up. 
I've got a nasty procedural solution working, but it's SO ugly that I'm 
almost embarassed to check it in to CVS....

Here goes:
I have this form with a bunch of checkboxes that represents a 2D Array:

[x] - Group 1
    [x] - Item 1
    [x] - Item 2
    [x] - Item 3

[x] - Group 2
    [x] - Item 1
    [x] - Item 2

Now, here's the ugly part:
 I need to tell the backend database what channels the user has 
UNCHECKED on this form. 
Since we only get back an array of what's been checked, there's some 
diffing in order.

Also, the API I'm talking to wants a list of ALL the unchecked channels 
each time I make the call -- it doesn't know about the current state of 
the checkboxes.

So, what I've been doing is assembling a group of hidden form fields 
that include ALL the groups and items involved, overloading the field 
values like this:
<input type='hidden' value='PARENT_<group_id>'>
and
<input type='hidden' value='<parent_group_id>_<item_id>'>

 From this, I can easily generate the two arrays to diff:
ALL Items, and Checked Items

I should also note that Item IDs are NOT unique, and I need to know 
which Group they got unchecked in.

Currently, I loop over each Group in All Items, checking to see if each 
Item ID is in the Checked Items array for that particular group.
If it isn't, it got unchecked, and I pop it onto a new array of excluded 
Item IDs.

Then I loop over THAT to make the excludeItem() calls that update the 
database.

So, my question is -- (i'm using PHP5, btw) is there a really good way 
to diff a 2-D array like this without using a bunch of nested foreach loops.
Keep in mind that I still need to know what Group the Item belongs to, 
as the Item IDs are not unique.

TIA,
Jeromie



The php_mysql group is dedicated to learn more about the PHP/MySQL web database 
possibilities through group learning.  
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php_mysql/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to