Ok try something like this (example code... i tried to comment in it as
much as possible):
for this example.. logs table structure:
id (primary, auto-increment)
description
---------------------
<?
include("db.php ");
//connect to db
if(!isset($_POS T['submit'])) {
//form isn't submitted
echo "<b>Logs</b><br><br>";
echo "<form action=\"\" method=\"post\" >";
$query = "SELECT * FROM logs";
$result = mysql_query($qu ery);
while($row = mysql_fetch_arr ay($result)) {
$id = $row['id'];
$description = $row['description'];
echo "Log: $description <input type=\"checkbox \" name=\"log_$id\ "
value=\"1\"><br >";
}
//get all log values, and present checkbox
//NOTE: checkbox values are prefixed with 'log_', explained later..
echo "<input type=\"submit\" name=\"submit\" value=\"Delete\ ">";
//input button
} else {
foreach ($_POST as $key => $value) {
if(strstr($key, 'log_')){
//if the value contains log_ then its used
if($value == '1'){
$id = str_replace("lo g_", "", $key);
//log_ prefix is removed to get the id
$query = "DELETE FROM logs WHERE id='$id'";
mysql_query($qu ery) or
die (mysql_error()) ;
//deleted..
}
}
}
echo "<b>Done</b>";
}
?>
---------------------
ok basics behind the script...
since theres an unknown number of form values the following is used:
foreach ($_POST as $key => $value) {
//code
}
....which loops through all the form elements and their values.
However this can cause a problems, because other form elements will be
picked up other than the checkboxes, such as the input button. THIS is
the reason that i prefixed all checkboxs with 'log_', so it can later
be checked.
i hope this is the kind of thing you are after ;)
-eilks
Angelos wrote:
<li><a href="transacti on.php?contCat= <? echo $contCat
?>&action=delet e&contSubCat= <? echo $contSubCat ?>&content_id=< ?php echo
$row['backup_id']; ?>"onClick="ret urn formConfirm('de l')">Del</a><input
name="<?php echo $row['backup_id']; ?>" type="checkbox" value="1">
</li>
Ok considering wi have the above code tha loops and lists a Number of DB
entries
how can we assign a checkbox in each of them and then retrieve each
checkboxs' value in order to delete the appropriate record when the form is
submited ?
THanks !!!