我已获得此分配,以通过用户输入对当前的SQL查询进行某种过滤。基本上,我正在寻找筛选选项,无论是某种菜单还是按钮,都没有关系。我的mssql如下:
SELECT TOP 10 Test_Database.Distributor, Test_Database.Value FROM Test_Database WHERE Test_Database.Week = '(USER INPUT GOES HERE)' GROUP BY Distributor ORDER BY Value desc
我如何使该WHERE语句成为用户输入?例如,客户希望看到某个分销商的给定价值,但要查看客户选择的周/月/年。
WHERE
问候
You can do that simply by introducing if else statement $where = ""; //receive filter option example $_GET['week'] //Do some sanitizing for $_GET['week'] if ($_GET['week']) { $where = "WHERE Test_Database.Week = $_GET['week']" } else if (somecondition) { $where = "some query"; }
//您可以通过串联$ where来添加多个条件,但要确保在哪里不重复
$query = "SELECT TOP 10 Test_Database.Distributor, Test_Database.Value FROM Test_Database $where GROUP BY Distributor ORDER BY Value desc "