Jump to content

checkbox array from mysql need to remember if checked on form self


giraffemedia

Recommended Posts

Hi

 

I have a form populated with an array of checkboxes (with labels). When I submit the form to the same page none of the checkbox values are remembered. What is the best way of achieving this?

 

If I echo the checked box values it tells me which ones were selected but I cannot get the actual boxes to remember if they were checked or not.

 

Here is what I have…

 

$checked = $_POST['issue'];
foreach($checked as $item) {
echo "Item $item was checked<br />";
}

while ($row = mysql_fetch_array($issue_query)) {

$issues[] = '<span style="display:block;margin:0px 0px 10px 60px;"><input name="issue[]" type="checkbox" style="width:auto;" value="'.$row['issue_number'].'">Issue <strong>'.$row['issue_number'].'</strong> '.$row['issue_month'].' '.$row['issue_year'].'<span>'; 

}

 

Any ideas?

 

Thanks,

 

James

$checked = $_POST['issue'];
foreach($checked as $item) {
echo "Item $item was checked<br />";
}

while ($row = mysql_fetch_array($issue_query)) {

$issues[] = '<span style="display:block;margin:0px 0px 10px 60px;"><input name="issue[]" type="checkbox" style="width:auto;" value="'.$row['issue_number'].'"'.(in_array($row['issue_number'],$_POST['issue']) ? ' checked="checked"' : '').'>Issue <strong>'.$row['issue_number'].'</strong> '.$row['issue_month'].' '.$row['issue_year'].'<span>'; 

}

 

You could try that. I'm not 100% sure, though. D:

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.