Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

106 users online



Mass delete

Mass delete

Currently viewing this thread: 1 (0 members and 1 guests)


v3x0rg

v3x0rg

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

BigToach

BigToach

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!

v3x0rg

v3x0rg

Pawn Coder
Status: Offline!

Example, please?

Edit: Here's what I've written so far:

PHP:

<?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)

BigToach

BigToach

Neversidian
Status: Offline!

here is the form

PHP:

<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:

<?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)

v3x0rg

v3x0rg

Pawn Coder
Status: Offline!

Got it working! Thanks!

___________________

- Moderator at the official AMX Mod X forums

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0081 seconds.