What I want to do:
Allow someone to select people by position and update the MySQL table to match their selections.
What I have:
An HTML Form with a series multi-select lists. The form passes a PositionID and a PersonID (drawn from a MySQL database). These forms all feed the same $_POST variable multidimenstional array. I have the lists all set, they even SELECT the people already in the tblPositionPerson.
On the page the form directs to, I have the tblPositionPerson in an array from a MySQL query.
MySQL Database Layout:
tblPosition:
-ID
-Position Name
tblPerson:
-ID
-Person Name
tblPositionPerson:
-ID
-PositionID (FK to tblPosition.ID)
-PersonID (FK to tblPerson.ID)
I finally finagled the arrays to be at least the same dimenstions. Here are the two arays:
$_POST Array ( [0] => Array ( [24] => 58 ) [1] => Array ( [13] => 23 ) [2] => Array ( [13] => 11 ) [3] => Array ( [12] => 58 ) [4] => Array ( [11] => 8 ) [5] => Array ( [10] => 16 ) [6] => Array ( [9] => 6 ) [7] => Array ( [8] => 16 ) [8] => Array ( [7] => 4 ) [9] => Array ( [6] => 15 ) [10] => Array ( [5] => 17 ) [11] => Array ( [4] => 2 ) [12] => Array ( [3] => 11 ) [13] => Array ( [1] => 10 ) [14] => Array ( [5] => 18 ) [15] => Array ( [13] => 14 ) [16] => Array ( [13] => 2 ) )
MySQL Array ( [0] => Array ( [1] => 10 ) [1] => Array ( [3] => 11 ) [2] => Array ( [4] => 2 ) [3] => Array ( [5] => 17 ) [4] => Array ( [5] => 18 ) [5] => Array ( [6] => 15 ) [6] => Array ( [7] => 4 ) [7] => Array ( [8] => 16 ) [8] => Array ( [9] => 6 ) [9] => Array ( [10] => 16 ) [10] => Array ( [11] => 8 ) [11] => Array ( [12] => 58 ) [12] => Array ( [13] => 11 ) [13] => Array ( [13] => 23 ) [14] => Array ( [24] => 58 ) )
How can I run through the $_POST array and update the MySQL table to match it (there could be some updates, adds, some deletes and some that stay the same)? I can't compare the arrays, because the key numbers won't match.
Thanks.