ksmatthews Posted September 27, 2007 Share Posted September 27, 2007 HI there, I have the following checkboxes where I am using an array called check[] ... <input name = "check[]" type = "checkbox" value = 'somevalue1' /> <input name = "check[]" type = "checkbox" value = 'somevalue2' /> <input name = "check[]" type = "checkbox" value = 'somevalue3' /> When selected by the user, I wish to delete the selected records using this code ... // capture checkbox data $data = $_POST['check']; // start delete loop foreach ($data as $key => $value ) { // create SQL string $SQL = 'DELETE FROM ' . $table . ' WHERE name = "' . $value .'"'; // run SQL query code goes here } This code works fine ! BUt the javascipt functionality that references it does not work ! What I would like to know is how I can do the same thing but AVOID using the check[] array, by using checkboxes like this ... <input name = "check" type = "checkbox" value = 'somevalue1' /> <input name = "check" type = "checkbox" value = 'somevalue2' /> <input name = "check" type = "checkbox" value = 'somevalue3' /> Has anyone got any good references for dealing with checkboxes in php ? thanks, Steven Matthews Quote Link to comment https://forums.phpfreaks.com/topic/70862-checkbox-blues/ Share on other sites More sharing options...
black.horizons Posted September 27, 2007 Share Posted September 27, 2007 i do indeed! i had the same problem only a couple of months ago. I'll try to find the code, but in the meantime check out my post with checkbox in the title! Quote Link to comment https://forums.phpfreaks.com/topic/70862-checkbox-blues/#findComment-356243 Share on other sites More sharing options...
black.horizons Posted September 27, 2007 Share Posted September 27, 2007 ok i used a for loop e.g. for($i=0;$i<10;$i++) { echo "<input type=\"checkbox\" name=\"red[$i]\"> } then to process: for($j=0;$j<10;$j++) { $valueofcheckbox = $red[$i]; if($valueofcheckbox=="on") { echo "$j is ON"; } else { echo "$j is OFF"; } } i'm sure you can figure out how to put this in a while loop if you're using a mysql recordset. Quote Link to comment https://forums.phpfreaks.com/topic/70862-checkbox-blues/#findComment-356246 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.