Titan85
01-17-2007, 11:48 PM
Ok, I am attempting to make a script that will allow multiple deletion at the same time (via check boxes). I am not really sure how exactly to do it, but so far what I have picked up from a few tutorials is this:
<?php
require('config.php');
$result = mysql_query("SELECT * FROM `m_delete` ") or die (mysql_error());
$count = mysql_num_rows($result);
echo '<table width="400">';
while($row = mysql_fetch_array($result)) {
extract($row);
echo '
<tr>
<td>'.$id.'</td>
<td><input type="checkbox" name="checkbox[]" /></td>
<td>'.$name.'</td>
<td>'.$email.'</td>
</tr>
';
}
echo '</table>
<br />
<input type="submit" name="delete" id="delete" value="Delete Selected" />
';
if($delete) {
for($i=0;$i<=$count;$i++) {
$del_id = $checkbox[$i];
$sql = "DELETE FROM `m_delete` WHERE `id` = '$del_id'";
$result = mysql_query($sql) or die (mysql_error());
}
if($result) {
echo 'Rows deleted!
<br />
<a href="'.$_SERVER['REQUEST_URI'].'">Back</a>';
}
}
mysql_close();
?>The problem I am having is that when I hit the "delete selected" button, nothing happens. Also, I would like to know what exactly this code does/means:
for($i=0;$i<=$count;$i++) {I have seen it lots of times, but can't quite figure out what $i is for. I appreciate any help :)
<?php
require('config.php');
$result = mysql_query("SELECT * FROM `m_delete` ") or die (mysql_error());
$count = mysql_num_rows($result);
echo '<table width="400">';
while($row = mysql_fetch_array($result)) {
extract($row);
echo '
<tr>
<td>'.$id.'</td>
<td><input type="checkbox" name="checkbox[]" /></td>
<td>'.$name.'</td>
<td>'.$email.'</td>
</tr>
';
}
echo '</table>
<br />
<input type="submit" name="delete" id="delete" value="Delete Selected" />
';
if($delete) {
for($i=0;$i<=$count;$i++) {
$del_id = $checkbox[$i];
$sql = "DELETE FROM `m_delete` WHERE `id` = '$del_id'";
$result = mysql_query($sql) or die (mysql_error());
}
if($result) {
echo 'Rows deleted!
<br />
<a href="'.$_SERVER['REQUEST_URI'].'">Back</a>';
}
}
mysql_close();
?>The problem I am having is that when I hit the "delete selected" button, nothing happens. Also, I would like to know what exactly this code does/means:
for($i=0;$i<=$count;$i++) {I have seen it lots of times, but can't quite figure out what $i is for. I appreciate any help :)