sort and outout array values
Posted: Tue Mar 14, 2017 1:06 pm
I have looked at and tried several examples but keep getting an output of "Array" no matter how I try it?
What it want to happen is get values from DB and put into array, then sort the array, then output all of the array for a drop down list.
What it want to happen is get values from DB and put into array, then sort the array, then output all of the array for a drop down list.
Code: Select all
$mfg_array = array();
$stmt = $db->prepare('SELECT mfg FROM manufactures');
$stmt->execute();
// put db values into array
while($row = $stmt->fetch()) {
$mfg_array[] = $row;
}
// sort array
sort($mfg_array);
// output array
foreach ($mfg_array as $mfg) {
echo '<option value="'.$mfg.'">'.$mfg.'</option>' ;
}