我有一個 mysql 表,其中包含一些列,dish_id、dish_description、dish_price、dish_category 等,我有一個查詢“order by categoria_piatto asc”,但這個查詢對我來說不好,我會自定義查詢順序,所以當獲取數組運行時顯示第一個結果dish_category = starters第二個結果dish_category =第一道菜第三個結果dish_category =主菜等...我能怎么做?與 group by 子句或其他?$portate = mysqli_query($con,"SELECT * FROM tablo_piatti where id_ristorante = '$idrist' and categoria_piatto = '$cat_piatto' and disponibilita = 'Si' order by categoria_piatto asc "); while($riga = mysqli_fetch_array($portate))
1 回答

一只甜甜圈
TA貢獻1836條經驗 獲得超5個贊
您可以使用CASE表達式。
...
ORDER BY CASE
WHEN categoria_piatto = 'antipasti' THEN
1
WHEN categoria_piatto = 'primi' THEN
2
WHEN categoria_piatto = 'secondo' THEN
3
...
END
...
而且,作為旁注,您應該學習使用參數化查詢。
- 1 回答
- 0 關注
- 134 瀏覽
添加回答
舉報
0/150
提交
取消