如何使用 PHP 和 MySQL 对表值进行排序


How to sort table value using PHP and MySQL?

我需要使用MySQL和PHP的一个订单来获取MySQL表值。我在下面提供我的表格。

db_cat:

id     cat_name   cat_id     order_no
1       aaa        10          1
2       ggg        10          30
3        fff       10           11

4      sss         10           12
5      ddd         10            5

在这里,我尝试使用查询根据order_no列值获取数据:

select * from db_cat where cat_id='10' order by order_no asc
但它给了我错误的订单数据,

例如(11,12,30,1,5),我应该在哪里获得像这个订单(1,5,11,12,30)这样的数据。

我的order_no数据类型是varchar

您可以按顺序使用强制转换

select * from db_cat where cat_id='10' order by cast(order_no as int) asc