A user can select as many cities as he would like and upon submit the checbox array is imploded into a comma separated string and that string is stored in one field.
If I want to build an update form to change the original selections … How do I pull these values, explode them and pre-check the checkbox list so it will reflect those values so I can start making changes …
Ok I just checked into this and it looks like I have to pull the data string … explode it … and compare the exploded array against my checkbox section to pre-check any of the checkboxes that would apply does this make any sense to you … I feel like I am almost there … or maybe I am delusional …
// EXPLODE THE STRING
$getcityarray = htmlspecialchars(stripslashes($business['cityarray']));
$explcitydarray = explode(",", $getcityarray);
//BUILD THE DYNAMIC CHECKBOX LISY
<?php
foreach ($cityarray as $key => $value) ------- // THIS ARRAY JUST PULLS ALL THE CITIES
{
echo '
<input type="checkbox" name="cityselection[] "id="cityselection[]" value="'.$value.'"
if (isset($explcitydarray) && in_array('.$value.', $explcitydarray)) {
checked="checked"}
/><label for="cityselection[]">'.$value.'</label><br />';
}
?>
I know I am missing some stuff but am I headed in the right direction?