Page 1 of 1

delete from database

Posted: Wed Jan 10, 2007 4:41 pm
by sweetcoz
hi everyone
i want to do something like in an inbox
if i click on a checkbox, it selects all checkboxes and it deletes the messages
and i can also select the message i wish to delete
how can i do that?
till now i have only been able to delete then one by one

Posted: Wed Jan 10, 2007 5:59 pm
by pickle
The most common reply you'll get is 'What have you tried'. This forum is great for helping people that help themselves. You'll be hard pressed to get an answer without showing you've given it your best go.

With that said... what have you tried?

Posted: Wed Jan 10, 2007 6:41 pm
by xinnex
I think what you are looking for, is a javascript like this:
http://www.somacon.com/p117.php

Then in the actual form, each checkbox-input would have to be named as an a array, eg:

Code: Select all

<form ..>
 <input type="checkbox" name="email[]" value="1"/> //value being the id of an email
 <input type="checkbox" name="email[]" value="2"/>
</form>
Which makes it pretty easy to loop through emails:

Code: Select all

foreach($_POST['email'] as $email_id)
{
	//delete email with id == $email_id
}

Posted: Wed Jan 10, 2007 7:21 pm
by Ollie Saunders
This...

Code: Select all

<input type="checkbox" name="email[]" value="1"/> //value being the id of an email
 <input type="checkbox" name="email[]" value="2"/> 
...is not necessarily supported by all browsers. To ensure it is put values in the subscripts. Like this:

Code: Select all

<input type="checkbox" name="email[0]" value="1"/> //value being the id of an email
 <input type="checkbox" name="email[1]" value="2"/>
Yeah you will have to use some JavaScript. To make all the checkboxes select. Add an onchange event to the primary checkbox (the one that will trigger all the others to check or uncheck) and in that event obtain the other checkboxes and iterate over them setting their values to true or false depending on the check value of the primary checkbox the event is attached to. Obviously if you don't know JS this isn't going to mean anything to you :P