> It is wrong to use that way of doing it John, cause this will delete ALL
> lines that where printed with a checkbox
> And also, if you are using a old version of PHP with register globals OFF,
> the _POST array will not be available

You are mistaken. $_POST['checkboxes'] will only contain those IDs for which
the boxes were checked. If you do not check a checkbox, it's value is not
sent at all. Try it please.

To create the checkboxes, you'd do something like this:

$result = mysql_query("select rowID from table");
while($row = mysql_fetch_row($result))
{ echo '<input type="checkbox" name="checkboxes[]" value="' . $row[0] .
'">"; }

Now, $_POST['checkboxes'] will be an array of rowID values for _only_ the
boxes that were checked (or $HTTP_POST_VARS['checkboxes'] or even just
$checkboxes, depending on your version and register_globals setting).

Then, use implode() to join them all in a string and add them to your DELETE
query.

---John Holmes...

> "1lt John W. Holmes" <[EMAIL PROTECTED]> a écrit dans le message de
> news: [EMAIL PROTECTED]
> > > 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.
> >
> > Easy one.. :)
> >
> > Make sure your checkboxes have the rowID as their value, then you can
> simply
> > do this:
> >
> > $query = "DELETE FROM table WHERE rowID IN (" .
> > implode(',',$_POST['checkboxes']) . ")";
> >
> > and run that query.
> >
> > You'll end up with something that looks like this:
> >
> > DELETE FROM table WHERE rowID IN (1,2,3,4,5)
> >
> > where the numbers will come from only the checkboxes that you selected.
> >
> > ---John Holmes...
> >
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


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

Reply via email to