|
Posted by Geoff Berrow on 12/11/06 09:27
Message-ID: <1165824944.590557.238040@l12g2000cwl.googlegroups.com> from
ameshkin contained the following:
>On the second page, whch is the form actin, I simply want to iterate
>through and pull which values are checked and run a sql command for
>each value.
>
>I have no idea how to do this. I assume you willl have to use a for
>each statement, but am having trouble programming this.
There is a clever little trick you can use. For your checkboxes you
give them a name like this
<input type='checkbox. name='del[]' value='3435'>
where value is the id of the record you want to delete.
By using the square brackets, all the values are conveniently placed in
an array. So here is the foreach (untested):
foreach($_POST['del'] as $value){
//ideally do some checking that the value is one that the user is
// allowed to delete here
$sql="DELETE from table WHERE id=$value";
if(mysql_query($sql)){
echo "record id $value deleted<br>";
}
else{
echo "Could not delete record id $value<br>";
}
}
--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
Navigation:
[Reply to this message]
|