
January 14th, 2006
08:15 AM
Pawn Coder
Status: Offline!
Mass delete
How would I delete entries in the database from a form when only certain ones are checked?
For example, in phpBB they have this feature for private messages. There's a bunch of check boxes going vertically and you can delete the ones that you check.
I hope you know what I'm talking about.
Thanks.
___________________
- Moderator at the official AMX Mod X forums

January 14th, 2006
02:31 PM
Neversidian
Status: Offline!
just have the checkboxes values be the ids of the rows that you want to delete as an array, then loop through that array and delete only the ids that are checked
___________________
Neverside Development Director
PHP Snippets
BigToach.com - IT WORKS, TOACHY!

January 14th, 2006
02:51 PM
Pawn Coder
Status: Offline!
Example, please?
Edit: Here's what I've written so far:
<?php
$sql = "SELECT * FROM ghw_priv_messages WHERE recieverid='$id' ORDER BY id DESC, `read` DESC";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)) {
$status_img = $row[read] ? "icons/user_gray.png" : "icons/user.png";
$subject = $row["subject"];
$sid = $row["senderid"];
$sender = name($sid); // Custom function that returns name
$mid = $row["id"];
$date = date("F j, Y", $row[stamp]);
echo '<tr>';
echo '<td><div align="center"><img src="'.$status_img.'"></div></td>';
echo '<td><div align="center"><b><a href="privmessage.php?sec=read&mid='.$mid.'">'.$subject.'</a></b></div></td>';
echo '<td><div align="center"><b><a href="members.php?mid='.$sid.'"><u>'.$sender.'</u></a></b></div></td>';
echo '<td><div align="center"><font size="1">'.$date.'</font></div></td>';
echo '<td><div align="center">
echo '<input type="checkbox" name="delete" value="checkbox">'; // checkbox
echo '</div></td>';
echo '</tr>;
}
?>
___________________
- Moderator at the official AMX Mod X forums
Last edited by v3x0rg, January 14th, 2006 04:50 PM (Edited 1 times)

January 14th, 2006
05:02 PM
Neversidian
Status: Offline!
here is the form
<form blah options>
<?php
$query = mysql_query('SELECT id, title FROM table WHERE something');
while($row = mysql_fetch_assoc($query))
{
echo '<input name="ids[]" type="checkbox" value="' . $row['id'] . '" />' . $row['title'] . '<br />';
}
?>
<input type="submit" />
</form>
then the form handler
<?php
// some error checking stuff
$ids = implode(', ', $_POST['ids']);
$query = mysql_query('DELETE FROM table WHERE id IN(' . $ids . ')');
?>
___________________
Neverside Development Director
PHP Snippets
BigToach.com - IT WORKS, TOACHY!
Last edited by BigToach, January 14th, 2006 05:10 PM (Edited 2 times)

January 14th, 2006
05:21 PM
Pawn Coder
Status: Offline!
Got it working! Thanks!
___________________
- Moderator at the official AMX Mod X forums