php - create a dropdown of unique options -
there 2 sqlite tables in db, units.id,unitname , departments.unit,department... units.id , departments.unit same.
the following list unitname each department, in example 10 of same unitname. looking slick way list unique unitnames. pardon ignorance because know easy..
<?php foreach ($departments $dept) { foreach ($units $unit) { if ($dept['unit'] == $unit['id']) { $options[$dept['id']] = $unit['unitname'];; } } } echo form_dropdown('unit',$options,'0'); ?>
some lovely detail;
$seenbeforearray[]; $size = sizeof($dept); ($i=0; $i < $size ; $i++) { if (in_array($dept[$i]['unitname'],$seenbeforearray[])){ unset($dept[$i]); } else { array_push($seenbeforearray, $dept[$i]['unitname']); } }
Comments
Post a Comment