我有PHP代码从下拉菜单中获取值并在查询中使用它们。然而他们被忽略了。这是一个例子:
$sortIn = $_POST['SortIn'];
$sortBy = $_POST['SortBy'];
$myquery = 'SELECT something FROM somewhere ORDER BY "$sortBy" "$sortIn"' ;
但是查询执行为$myquery = 'SELECT something FROM somewhere'
答案 0 :(得分:1)
更改为:
$myquery = "SELECT something FROM somewhere ORDER BY $sortBy,$sortIn";
因为在单引号中$sortBy
和$sortIn
并未将其解释为变量。
答案 1 :(得分:0)
尝试此查询:
$sortIn = $_POST['SortIn']
$sortBy = $_POST['sortBy']
$myQuery = "SELECT something FROM somewhere ORDER BY '".sortBy."','".SortIn."'";