|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
delete multiple records
Hi guys,
I am trying to pass multiple values by using a variable from one file to another.. in one file, i set all checkboxes with variable name 'remove' (use while loop).. each check box comes with differen value.. when the user check more than one check box, it will delete the records in db according to the value of the checkbox.. in short, i want my system to perform a task like what yahoo mailbox can do.. when we check the checkbox next to the email that u wanna delete and then click on remove button.. after that, the email selected will be removed.. this is the code where i used to capture the values of 'remove' being pass from other file ... but it doesn't seem to work coz this error occured Invalid argument supplied for foreach() my code: if (isset($_POST['remove'])) { $total = count($_POST['remove']); $removed = 0; if ($total == 0) { die('You did not select any records...'); } else { foreach ($_POST['remove'] as $val) { $sql = "DELETE FROM transaction WHERE code = '$val'"; $res = mysql_query($sql); if (mysql_affected_rows() > 0) { $removed++; } } i am wondering is it i can not use same variable for the checkbox that with different values ??? or could u guys give me an idea where i can get a reference how to perform this kind of task ?? please advise. |
|
#2
|
|||
|
|||
|
Yes, you can use same name with different values, but. it has to be like this :
checkbox 1 : name=x[0] checkbox 2 : name=x[1] etc.... on PHP $val = $_POST['x'] $val[0] <= will print x[0] value $val[1] <= will print x[1] value Hope that help wink, Less than $1 / month web hosting URL |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > delete multiple records |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|