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 :
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.