Jump to content

[SOLVED] Multiple database queries from a form post


magga

Recommended Posts

Hi I have a page which lists rows from a database.

I then have a form where you can select certain rows and delete them.

What I want to do is enable users to delete multiple rows from one form which currently it is not doing.

These are the bits of code that might be useful in helping me:
[code]
$notification_id = $_POST['notification_id'];
mysql_query("DELETE from notifications where id='$notification_id'");[/code]

And from the form:
[code]<input type="checkbox" name="notification_id" value="<? echo $row['id'] ?>">[/code]
(the $id in this comes from another query and does work)

It is currently working but you can only delete one row at once obviously because the $notification_id is only holding one value on the post.

Do I need to put the values into an array then run the delete query for each value ? If so, how do I go about this ?

Thanks in advance.

Create a "notification_id[]" field (notice brackets) for each record, that will make the field an array.

Then change you query as follows:
[code]$notification_ids = implode(",",$_POST['notification_id']);
mysql_query("DELETE FROM notifications WHERE id IN ({$notification_ids})");[/code]
  • 1 month later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.