I have a database filled with records and by using this MySQL-syntax:
public static function allfood($db) {
$sql = "SELECT DISTINCT sort, sortname FROM tblDishes WHERE foodanddrinks = 'e'";
$result = $db->listing($sql);
return $result;
}
I get all the results ordered alphabetically. But I would like to determine my own order. For example Rabbitshould be displayed before Apple. Is there a SQL-syntax which allows me to organize my own order of display?
EDIT
This is stated in my dbconnections.phpfile.
public function listing($sql) {
$result = mysql_query($sql, $this->_connection);
while($row=mysql_fetch_array($result)) {
$return[] = $row;
}
return $return;
}
And this is the thing I tried, but I get an error in the dbconnections.php file
public static function allfood($db) {
$sql = "SELECT DISTINCT sort, sortname FROM tblDishes WHERE foodanddrinks = 'e' order by case sortname
when 'Rabbit' then smth1
when 'Apple' then smth2
when 'Fish' then smth3
when 'Pasta' then smth4
when 'Snacks' then smth5";
$result = $db->listing($sql);
return $result;
}
This may help you: