I am generating a list of cuisines like this:
$lists='';
$stmt="SELECT cuisine_id, cuisine_name, cuisine_name_trans FROM db_cuisine";
if ( $res=$DbExt->rst($stmt)){
if ($list){
foreach ($res as $val) {
$cuisine_json['cuisine_name_trans']=!empty($val['cuisine_name_trans'])?
json_decode($val['cuisine_name_trans'],true):'';
$lists[$val['cuisine_id']]="".qTranslate($val['cuisine_name'],'cuisine_name',$cuisine_json);
}
return $lists;
}
return $res;
}
return false;
The list is then returned as:
1: "American"
5: "Sandwiches"
6: "Barbeque"
8: "Italian"
9: "Mexican"
10: "Sushi"
11: "Burgers"
13: "Japanese"
(The IDs are according to the database ID). I am trying to sort them now descending by name but I can't seem to get it done with sort as it needs a key name. How do I do that?
$list,$cuisine_jsonand$lists? Where are they defined? What doesqTranslate()do?$listis just a true/false.$listsis defined with$lists='';and$cuisine_jsoncomes fromcuisine_name_trans.$listsis a string, you're going to run in to problems with that$lists[$val['cuisine_id']]bit. I'd recommend an array instead, ie$lists = [];