SELECT WHERE'"。$ Variables。"' =' YES'

时间:2015-11-13 18:50:20

标签: php select mysqli

我想从表格中选择任何一行 它有column (admin, normal, adviser)="YES"

所以我创建了array $level=array(admin, normal, advuser) 如果用户是admin ==> $level[0]

$query="SELECT * FROM LibraryFolders WHERE '".$level[0]."'='YES'";

如何将变量作为列键

2 个答案:

答案 0 :(得分:2)

删除列名称周围的'

$query="SELECT * FROM LibraryFolders WHERE ".$level[0]." = 'YES'";

答案 1 :(得分:1)

我认为这应该有效:

$filter = "";
if($user == 'admin') {
    $filter = " {$level[0]} = 'YES' ";
}
elseif($user == 'normal') {
    $filter = " {$level[1]} = 'YES' ";
}
else {
    $filter = " {$level[2]} = 'YES' ";
}
$query= "SELECT * FROM LibraryFolders WHERE {$filter} ";

但我们需要更多信息:你如何获得阵列?

希望有所帮助