i have one html table with all the rows value from a specific database table.
I created a html table column to eliminate a specific row from the database, inside this column exists a checkbox to check and eliminate multiple table rows from the database.
But i'm having some problems, i can only delete the last row, example: Lets imagine that you check the second row, and you click at submit button and nothing happens.
But if you check the last inserted row, and you click submit, it deletes the row from the database.
I just can delete the last row, i can't delete multiple rows by checking a specific number of checkboxes.
I did this:
I'm using the MVC structure:
View:
<form method='POST'>
<?php
echo "<td><input style='width: 50px;' class='delete' value='delete' type='submit' name='del[]' /></td>";
foreach($editjoarray as $key){
echo "
<table>
<tr>
<td> ".$key['id']."</td>
<td><input type='checkbox' name='delete[]' value=".$key['id']." /></td>
</tr>
</table>
</form>";
}
Model:
function fname(){
if(isset($_POST['del']) && !empty($_POST['delete'])) {
{
$checkbox = $_POST['delete'];
$countCheck = count($_POST['delete']);
for($i=0;$i<$countCheck;$i++) {
$del_id = $checkbox[$i];
echo $del_id;
$sql = "DELETE FROM mytable WHERE id=$del_id";
$exe = mysql_query($sql) or die(mysql_error());
}
}
}
printFunction();
}