Home > Archive > PHP SQL > August 2004 > Select rows to delete with a checkbox
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Select rows to delete with a checkbox
|
|
| nezbie 2004-08-18, 3:57 pm |
| I've been trying to search for a decent and clear source of help
for something as simple as deleting rows with checkboxes. Please, can
someone give me a helping hand here?
I have this kind of "code" already, actually the delete
page. I'll try to simplify it as much as I can.
pages_row[page_id"] is a 10 digit randomly generated
id received from database talbe "pages"
<?php
if (!submit) // if the delete command has been submitted
(button pressed)
{
?>
<table cellpadding="4" cellspacing="0"
border="0">
<form action="index.php?admin=pages&sub=delpage"
method="POST">
<?php while(pages_row =
mysql_fetch_array(pages_result)) { ?>
<tr>
<td>
<input type="checkbox" name="del[]"
value="<?php echo pages_row["page_id"];
?>"><?php echo pages_row["page_title"];
?>
</td>
</tr>
<?php } ?> // to end the while-loop
</table>
<input type="submit" name="submit"
value="Delete selected">
<?php } // close the submit check
else // if the page has been submitted, delete all the checked
page_id's
Hah, I need a code here. I've tried quite a many examples but
they were all.. well.. any help, please?
} // end the delete loop
?>
:: Be patient with me, I'm new to PHP and MySQL :: :)
----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums
| |
| Barand 2004-08-18, 3:57 pm |
| --------
# if delete selected chosen
{
ids_to_delete = join(',' ,
_POST['del']);
mysql_query("DELETE FROM pages WHERE
page_id IN (ids_to_delete))";
}
--------
Suppose 1, 3 and 5 are selected. These are in the array
_POST['del']. The first line create a string
"1,3,5". The next line deletes ids in that list.
hth
Barand
http://members.aol.com/barryaandrew...agridguide.html easy
data tables - and more
----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums
|
|
|
|
|