ORDER BY CASE不使用php GET

时间:2016-08-21 20:35:58

标签: php mysql

我在PHP页面中显示了一个MYSQL数据库,按照#34; Seat"。

列排序。

如果用户点击"按名称排序"我希望如此链接,表现在按此列命令。

<?php
include "connect.php";

$resulted = mysqli_query($con, "SELECT * FROM guests ORDER BY case WHEN Seat = '' THEN 2 ELSE 1 END, Seat");

if (isset($_GET['Name'])) {$resulted = mysqli_query($con, "SELECT * FROM guests ORDER BY case WHEN Name = '' THEN 2 ELSE 1 END, Name");}
?>

<a href='?Name=true'>Order By Name</a>

当用户点击该链接时,该表确实按名称排序,但由于某些奇怪的原因,它会逐步输入ORDER BY CASE语句。

为什么?

1 个答案:

答案 0 :(得分:0)

而不是检查Seat = ''尝试检查IS NULL

case WHEN Seat IS NULL THEN 2 ELSE 1 END

(OR)

case WHEN Seat IS NULL OR Seat = '' THEN 2 ELSE 1 END