dmikester1 Posted March 28, 2010 Share Posted March 28, 2010 I've been trying to figure this problem out for a few hours and I'm getting pretty frustrated. I have a form with a bunch of checkboxes associated with a given athlete in a given event. All the checkboxes are initially checked. If any get unchecked and then the submit button is hit, it is supposed to delete the entry in the database for that athlete for that given event. I'm to pass over an associate array containing the athlete ID connected with an event ID in a session var usin. But I'm trying to figure out how to get a similar array passed over for the checkboxes that are or are not checked. I can grab the athlete IDs that are associated with the checkboxes that are checked. But I also need the event IDs to be matched up with the athlete IDs on the other side. I've tried posting an associative relay and had no luck. Can someone help me out? Thanks Mike Quote Link to comment Share on other sites More sharing options...
zeodragonzord Posted March 29, 2010 Share Posted March 29, 2010 As you've stated, you can only get the checked checkboxes to send data from the form. So this is what you have: the array of all values you used to generate the checkboxes the values from the checked checkboxes when the form is submitted When the form is submitted, that take the first array, loop it and remove the rows from the array based on what was checked. This will leave you with rows that have been unchecked. Quote Link to comment Share on other sites More sharing options...
dmikester1 Posted March 29, 2010 Author Share Posted March 29, 2010 That makes sense. However there is still a problem. There can be multiple checkboxes with the same value(athlete ID). Only when you compare them against the event IDs do you get a unique instance. So I need to get the array of checked checkboxes matched up with their associated event IDs passed over to the other side. Thanks Mike Quote Link to comment Share on other sites More sharing options...
andrewgauger Posted March 29, 2010 Share Posted March 29, 2010 EventIDs could be unique arrays that contain values of checked athletes. handler can parse those eventIDs into a single array so lets say you have passed Event_123[]="1,2,3,4"; Event_456[]="1,2,4"; Event_789[]="1"; which came from a grid of: 1 2 3 4 1 2 3 4 1 2 3 4 Lets assign the variable $completeGrid that value {$completeGrid=array(array(1,2,3,4),array(1,2,3,4),array(1,2,3,4))} So you know that you want the unchecked array to be [ NULL 3 2,3,4 ] This example is pretty simple, I don't use assoc's like I would have, but here is how I am generating the multidimensional array to compare values: $checks=array(); foreach ($_POST as $key => $arg) { if (substr($key,0,6)=="Event_"){ checks[]=$arg; } Remember to preserve order with this example, which is why I would think it would be better to use associatives, but this can also be included as part of your POST handler. Then just do this to get the superArray: superArray=array(); for ($i=0;$i<count($completeGrid);$i++){ $superArray[$i]=array_diff($completeGrid,$checks) } The part I'm not sure about is if the example of translating multiple single dimensional arrays into a multi-dimensional array is compatible with your current code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.