mysql按时间排序不正确,php mysql按时间戳排序不正确

I have database records such as below

Name Date(timestamp) Time(timestamp)

I want to order them by time DESC. But it shows me incorrect order. It shows now:

Name 19:00

Other 18:30

One more 19:00

As you can see hours are not going from earliest to latest. I want it to be like this:

Other 18:30

Name 19:00

One more 19:00

What am i doing wrong?

SELECT * FROM table WHERE date='".$date."' ORDER BY book_time DESC

解决方案

Are you sure that select only for the date that you want? Because I think that select multiple date not only one.

Also for what you want you need to use ASC instead of DESC.

Because I have try and it's work for me. This is my simple code :

$sql = "SELECT * FROM test WHERE date = '2016-02-10' ORDER BY time ASC";

$res = $DB->query($sql);

while($enr = $res->fetch()){

var_dump($enr);

}

With this DB :

Wheqx.png

And the result is :

array (size=8)

'id' => string '4' (length=1)

0 => string '4' (length=1)

'date' => string '2016-02-10' (length=10)

1 => string '2016-02-10' (length=10)

'time' => string '01:00:07' (length=8)

2 => string '01:00:07' (length=8)

array (size=8)

'id' => string '3' (length=1)

0 => string '3' (length=1)

'date' => string '2016-02-10' (length=10)

1 => string '2016-02-10' (length=10)

'time' => string '02:03:05' (length=8)

2 => string '02:03:05' (length=8)

The result is order in the ASC order like you want

Hope that helps you.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值