RE: [PHP] deleting multiple items from a database
[snip] function deleteFiles() { foreach($_POST['stack'] as $i) {//This should work but I can't tell if it is or isn't mysql_query(DELETE FROM uploads WHERE upload_id = . $i); } [/snip] Try print_r $_POST['stack'] and see what you get. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] deleting multiple items from a database
On Wed, 2004-10-13 at 16:11 -0400, Adil wrote: function deleteFiles() { foreach($_POST['stack'] as $i) {//This should work but I can't tell if it is or isn't mysql_query(DELETE FROM uploads WHERE upload_id = . $i); } header(Location: http://; . $_SERVER['PHP_SELF']);//forces a page refresh to show the file list without the items that were deleted. } For sanity of your mysql database, you might consider making this one query. Something like DELETE FROM table WHERE id IN (32,34,46,432,35); generating your list of numbers/ids from your array... -Robby -- /*** * Robby Russell | Owner.Developer.Geek * PLANET ARGON | www.planetargon.com * Portland, OR | [EMAIL PROTECTED] * 503.351.4730 | blog.planetargon.com * PHP/PostgreSQL Hosting Development / signature.asc Description: This is a digitally signed message part
Re: [PHP] deleting multiple items from a database
* Thus wrote Adil: As far as the code goes what I'm doing is retrieving each record from the database and assigning the value attribute of each checkbox the unique id from the database. From that point on, when a checkbox is checked and the delete button is pressed, I push each checked unique id into an array and then call a function that cycles through the array and deletes each database entry. The last step is a simple page refresh. I'm posting some of the more relevant sections of the code I've used below: echo form action=\{$_SERVER['PHP_SELF']}\ method=\post\; //form declaration echo input type=\submit\ value=\Delete\value=\Submit\; //The delete button tdinput type=\checkbox\ value=\{$row['upload_id']}\/inputbr//td;//This is what the checkbox is coded as This is your problem, you need to give the checkbox a name: input type=checkbox name=stack[] value=... When the form is submitted $_POST['stack'] will contain an array of items that were checked. Curt -- Quoth the Raven, Nevermore. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php