Re: Checkboxes to gather rows to delete

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You best bet is to do this:

List all your rows with the ID to delete in the NAME of the checkboxes and
at the same time build a list seperated by "," with your IDs so you can use
that list the EXPLODE function for PHP:

Echo "<input type=\"checkbox\" name=\"id" . $row[id] . "\" value=\"1\">";
$idList .= $sep . $row[id];
$sep = ","

This little snippet is used to draw your list of checkboxes, the other lines
are used to build a list of IDs in the form of:
1,2,6,7,9,10,34,65,101

When this step is done, at the bottom of your form, draw a hidden field with
the list of IDs as the value

Echo "<input type=\"hidden\" name=\"idlist\" value=\"$idList\">"

Then in THE OTHER SCRIPT, the one used to delete
you can explode the list of Ids and loop the array to get all values the
user checked:

$array_id = explode("," $idlist");
foreach($array_id as $id){
    if(${"id" . $id} == 1){
        //INSERT YOUR CODE TO DELETE HERE, the id to to delete is in $id
    }
}

The ${"id" . $id}is a way to get a variable by it's name even if you don't
know it, all thats inside the {} are considered the variable name. Then
check if that variable contains 1 or "". 1 meaning it was checked and ""
meaning it wasn't

Have a nice day
Mathieu Dumoulin
Web solutions programmer analyst

"Lewis Watson" <php@visionsix.com> a écrit dans le message de news:
003a01c2dc1a$4be7fb70$a977ca41@vsis169...
> I have a mysql database with a table using one column as a primary key.
> (rowID). On a php page I use a query to  list all of the rows of the table
> and have a checkbox beside each  row that should be used to check if you
> would like to delete this row. Can someone give me an example using post
> to pull the boxes that need to be deleted.
> Thanks!
> Lewis
>
>



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux