delete from database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sweetcoz
Forum Newbie
Posts: 4
Joined: Tue Jan 09, 2007 4:22 am

delete from database

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
xinnex
Forum Commoner
Posts: 33
Joined: Sun Jan 07, 2007 7:38 pm
Location: Copenhagen, Denmark

Post 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
}
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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
Post Reply