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

Link to comment
Share on other sites

$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:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.