I have a page where I am displaying sql results as a table. I have it so that all the options are checked on default. However, when the user unchecks some locations and submits the form, he/she won't know what locations they're filtering on because all the checkboxes will still be checked. How can I make it so that only the checkboxes that were checked retain their value after the form is submitted? Thank you
Here's my page so far:
<?php
$start=_GET['start'];
$end=_GET['end'];
if(empty($start)){
$start=date("Ym");
}
if(empty($end)){
$end=date("Ym");
}
$places=array();
if(!empty($_GET['cities'])){
foreach($_GET['cities'] as $loc){
array_push($places,$loc);
}
}else{
$places=('CHI','DET','LA','NYC','DALLAS','SPR','PHI');
}
?>
//html
<form method='GET'>
START:<input type='text' name='start' value= '<?$start?>'>
END: <input type='text' name='end' value='<?$end?>'>
<input type='checkbox' name='cities[]' value='CHI' checked>CHICAGO
<input type='checkbox' name='cities[]' value='DET' checked>DETROIT
<input type='checkbox' name='cities[]' value='LA' checked>LAS ANGELES
<input type='checkbox' name='cities[]' value='NYC' checked>NEW YORK
<input type='checkbox' name='cities[]' value='DALLAS' checked>DALLAS
<input type='checkbox' name='cities[]' value='SPR' checked>SPRINGFIELD
<input type='checkbox' name='cities[]' value='PHI' checked>PHILIDELPHIA
<input type='submit' value='Filter'>
</form>
<?
$SQL="SELECT NAME,
ID,
PHONE,
EMAIL,
EVENT,
LOCATION
FROM SHOPPERS
WHERE LOCATION IN ('".implode("', '", $places)."')
AND EVENT BETWEEN '{$start}' and '{$end}'
AND ID BETWEEN '25687' AND '28050'
";
//and then fetch array to print out results...
.....
?>