I am creating a simple drop-down menu displaying names:
$sql = "SELECT id,
name
FROM team
WHERE 1";
$stmt = $mysqli->prepare($sql);
if ($stmt) {
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($id, $name);
while ($stmt->fetch()) {
echo '<option value=\"$id\">'.utf8_encode($name).'</option>';
}
} else {
header('Location: ../../error.php?err=the database is corrupted');
}
I want to sort the option by alphabetic order. I am not sure which function should I use to sort the object before the loop. Any ideas?