[eluser]123wesweat[/eluser]
Hi,
In a model i have a function which returns a table with colors and checkboxes. The table is dynamically parsed by reading out colors in tableB (fields are colorID and colorName).
Selected checkboxes are stored as a serialized array in tableA.fieldColors.
I am also using the preset_checkbox helper.
code so far
Code:
function get_color_checkboxes()
{
//first check if colors are already set in db
$query = $this->db->query("SELECT color FROM tableA");
$res = $query->result();
$colorsDB=unserialize($res[0]->color);
//testing
foreach($colorsDB as $colorSelected ) {
echo $colorSelected;
}
$preselect = 'red';//works
die();
//.end testing
$this->db->select('id ,colorName');
$colors = $this->db->get('tableB')->result();
$msg = '<table>';
foreach ($colors as $color) {
$msg .= '<tr><td> <input type="checkbox" value="'.$color->colorName.'" name="colors[]" '. preset_checkbox('segments[]', $color->colorName, $preselect).' />
<span class="">'.$color->colorName.'</span></td></tr>';
}
$msg .= '</table>';
return $msg;
}
How do i set the $preselect in the preset_checkbox from the unserialized array??