I want to loop thru ALL results and then check the ones that are selected from the database (2 tables). Right now it displays all results and checks the right ones but my results are duplicated. What can I do to fix this?
What Im getting now
x item1
item1
item1
item2
x item2
item2
item3
item3
x item3
etc...
Result I want
x item1
x item2
x item3
item4
item5
x item6
etc
Code Im using
<? foreach($modules as $key => $module): ?>
<? foreach($selectedmodules as $key => $selected):?>
<input type="checkbox" name="" value="<?=$module->module_id?>"
<?=($selected->module_sel_id == $module->module_id ? 'checked="checked"' : '') ?>/><?=$module->module_name?><br />
<? endforeach; ?>
<? endforeach; ?>
Model (Im using Codeigniter)
public function getModules()
{
$this->db->select('*');
$this->db->from('module_type a');
$this->db->join('module b', 'a.type_id = b.type_id');
return $this->db->get()->result();
}
public function getSelectedModules($id)
{
$this->db->select('b.module_sel_id');
$this->db->from('module a');
$this->db->join('module_select b', 'a.module_id = b.module_sel_id');
$this->db->where('b.product_id', $id);
return $this->db->get()->result();
}