Page 1 of 1

Cycling through checkbox results

Posted: Thu Feb 16, 2006 2:46 am
by rsmarsha
I have information displayed in a table with a checkbox by each one. To cycle through them, atm i'm using : -

Code: Select all

while(list($key) = each($_POST["add"])) 
{ 
//Query here using $key
}


//checkbox looks like
echo '<input type="checkbox" name="add['.$lrow['product_id'].']" value="add">';
Does this look ok? Or is there a better way to do this?

The checkboxes will identify different products with an id.

The other problem is to do with updating. Products are selected from a list to be added to a form, then inserted into the database. If the list of products is viewed again, i have made the ones already inserted show as checked in the checkbox alongside each product.

The problem then is : -

If a product is deselected then it needs to be removed from the db.

If a product doesn't change, then it would have to run an update query.

If a product is added it would run an insert.



With the above in mind, would it be better to run a delete query to remove all current products and then run an insert to insert the posted checked products?