PHP MYSQL预备语句ORDER BY问题

时间:2019-02-26 09:12:31

标签: php mysql

我创建了一个准备好的选择查询,但该查询似乎未使用DESC,或者我的bind_param结构错误。

<?php
$sql = "SELECT t.table_id, t.table_number, s.statistic_id, s.operator, s.table_id, s.start_time, s.end_time, s.amount, s.status, s.date, s.player FROM tables AS t INNER JOIN statistics AS s ON t.table_id=s.table_id WHERE s.operator = ? AND s.status = 1  ORDER BY s.statistic_id DESC";
$stmt = mysqli_prepare($dbc, $sql);
mysqli_stmt_bind_param($stmt, "i", $_SESSION['user_id']);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $table_id, $table_number, $statistic_id, $operator, $table_id, $start_time, $end_time, $amount, $status, $date, $player);
while(mysqli_stmt_fetch($stmt)):
     echo $statistic_id; //I want to sort statistic_id as DESCENDING ORDER However, it sorts as ascending order
?>

我得到的样本输出

 #  Стол №  Начало  
 1  Консоль 2019-02-26 13:12:21
 2  Консоль 2019-02-26 13:12:25
 3  Консоль 2019-02-26 13:12:29 
 4  Консоль 2019-02-26 13:34:26

我想以最后一行为例

  # Стол №  Начало  
  4 Консоль 2019-02-26 13:34:26
  3 Консоль 2019-02-26 13:12:29 
  2 Консоль 2019-02-26 13:12:25
  1 Консоль 2019-02-26 13:12:21

我这样做正确吗?

0 个答案:

没有答案