I'm doing some research on multiple checkboxes that update multiple records in a DB. That is... first list all the rows from table/tables that match the SELECT query. Use PHP to output form with checkbox instead of value for one column. Then user checks one or several boxes, and hits "Submit". The data (array) is then sent to the DB through a function.
So... I think I have the output of the checkbox-part of the form correct.
Please correct me if I'm wrong. The background for the entire HTML-table is values from two MySQL-tables, and is dynamically created.PHP Code:<?php
echo '<input type="checkbox" name="voided[]" value="'.$row['invoice_no'].'">'
?>
Now... the UPDATE query... I've seen two ways of doing this, but if I understand correctly, the best aproach is the IN() way.
Example taken from a forum...
Now I was thinking of something along the lines of...PHP Code:if (count($del)) {
$str = implode(",",$del);
$result = mysql_query("DELETE FROM posts WHERE id IN($str)" );
}
UPDATE invoices SET voided=1 WHERE invoice_no IN()
instead of the delete in the above example. I'm just not really sure on how to put it together. There isn't much information about IN() at mysql.com, but what I found confirmed its usabillity.
One other thing... is it really true that non-checked checkboxes are ignored when submitting a form? I'm using 1 as signifying marked/checked/true and 0 or blank as not checked/false. (Seemed logical at the time). I have tried checkboxes for changing from 1 to 0 and back, so that part is working. Not pretty, but working. One checkbox - one form.




let me try it and see how it goes...


Bookmarks