Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiple deletes from a table

Status
Not open for further replies.

martinb7

Programmer
Jan 5, 2003
235
GB
Hi, how can you delete multiple entries from a table when a user submits a form?? i know you can use checkboxes to do it but how??

the checkbox would have the value in it. but how do you make it delete multiple when one or more checkboxes are checked and a user submits the form??

any ideas??

thanx


Martin

Computing help and info:

 
Hi,

I assume you are wanting to delete multiple database entries.

Simply output each record onto one page and use the db id as the value for each checkbox. The name of the checkboxes will be an array.

Example:

Some content <input type="checkbox" name="delete[]" value="db_id"><br>
Some content <input type="checkbox" name="delete[]" value="db_id"><br>

etc

Then when you submit that to a page you simply run through the array delete[] and delete each record like so:

// do the database connection etc first
Code:
for ($i=0; $i < count ($delete); $i++)
     {
     // sql delete goes here
     $sql = "DELETE FROM `table_name` WHERE `id` = '" . $delete[$i] . "'";
     $query = mysql_query($sql);
     }

// close db connection now.

That's it.

Hope this helps!

NATE


mainframe.gif


Got a question? Search G O O G L E for links to the fastest answers: www.google.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top