我不确定我的错误在哪里,但是它说Sort是未定义的,也是一个关于无效查询的错误:Erreur desyntaxeprèsde'GROUPBY Mall ORDER BY CounterDESC'àlaligne 1
以下是我的代码关于商店展示的摘录。
if(isset($_GET['formSubmit']))
{
$varStats = $_GET['formStats'];
$errorMessage = "";
switch($varStats)
{
case "ByAMEX": $sort = "AMEX = 1"; break;
case "ByBDOTerminal": $sort = "BDOTerminal = 'YES'"; break;
case "ByResto": $sort = "Resto = 'YES'"; break;
case "ByCashOnly": $sort = "Cash = 'YES'"; break;
case "ByPOSNotSeen": $sort = "POSNotSeen = 'YES'"; break;
}
$conn = db_connect();
sortMall($conn, $sort);
db_disconnect($conn);
exit();
}
以下是我初始化Sort函数的摘录:
function sortMall($conn, $sort)
{
$table = "test";
$column1 = "StoreName";
$column2 = "Mall";
$query1 = "Select $column2, Count($column1) AS Counter from $table where $sort GROUP BY $column2 ORDER BY Counter DESC";
$result = mysqli_query($conn, $query1);
if ($result == FALSE)
{
echo "Invalid query: " . $conn->error;
echo "<br/>";
return;
}
我实际上有另一个函数几乎使用相同的语法完成相同的功能,它的工作原理。我不知道为什么会这样。
答案 0 :(得分:0)
$varStats
可能不属于您定义的情况,请添加default
案例
如果是这样,$ sort并未定义为您的问题
答案 1 :(得分:0)
试试这个
if(isset($_GET['formSubmit']))
{
$varStats = isset($_GET['formStats']) ? $_GET['formStats'] : '';
$errorMessage = "";
switch($varStats)
{
case "ByAMEX": $sort = "AMEX = 1"; break;
case "ByBDOTerminal": $sort = "BDOTerminal = 'YES'"; break;
case "ByResto": $sort = "Resto = 'YES'"; break;
case "ByCashOnly": $sort = "Cash = 'YES'"; break;
case "ByPOSNotSeen": $sort = "POSNotSeen = 'YES'"; break;
default: $sort = 'yourvalue';// default case
}
$conn = db_connect();
sortMall($conn, $sort);
db_disconnect($conn);
exit();
}
可能是您的$sort
未获得switch
答案 2 :(得分:0)
试试这个,
if(isset($_GET['formSubmit']))
{
$varStats = isset($_GET['formStats']) ? $_GET['formStats'] : '';
$errorMessage = "";
$sort = "1=1";
switch($varStats)
{
case "ByAMEX": $sort = "AMEX = 1"; break;
case "ByBDOTerminal": $sort = "BDOTerminal = 'YES'"; break;
case "ByResto": $sort = "Resto = 'YES'"; break;
case "ByCashOnly": $sort = "Cash = 'YES'"; break;
case "ByPOSNotSeen": $sort = "POSNotSeen = 'YES'"; break;
default: $sort = 'yourvalue';// default case
}
$conn = db_connect();
sortMall($conn, $sort);
db_disconnect($conn);
exit();
}