This code picks up the ID of the check box checked correctly, however it chooses the select dropdown from my first select not the one I changed. Is there a way to fix this? Im using
<select name="status[]"><option value="1">active</option><option value="0">inactive</option></select>
here is my process code.
if (isset($_POST['submit'])) {
// find out how many records there are to update
$size = count($_POST['id']);
// start a loop in order to update each record
$i = 0;
while ($i < $size) {
// define each variable
$id = $_POST['id'][$i];
$status= $_POST['status'][$i];
// do the update and print out some info just to provide some visual feedback
$query = "UPDATE users SET status = '$status' WHERE id = '$id' LIMIT 1";
mysql_query($query) or die ("Error in query: $query");
print "$status | $id<br /><br /><em>Updated!</em><br /><br />";
++$i;
}
mysql_close();
}
I agree with the comments, however, I’ll just provide a quick answer to the question.
I’d do something like this for simplicity in the HTML. The array indices can simply echo from a counter in PHP or entered statically if it won’t change based on anything else. Simply increase this index with each item.
Now for the PHP
EDIT:
I forgot to mention you can set the value of the checkbox to whatever you need it to be. Just be sure the
if($value==1)checks for a valid result (for example>0if all of your Id’s are positive).