0

i want to select from table any row that has column (admin, normal, adviser) and ="YES"

so i created an array $level=array(admin, normal, advuser) if the user is admin ==> $level[0]

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

how to but a Variables as column key

Nana Partykar
  • 10,556
  • 10
  • 48
  • 77
Moaz Mabrok
  • 697
  • 10
  • 32
  • 1
    Read this: http://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks – Marc B Nov 13 '15 at 18:52

2 Answers2

2

Remove the ' around the column name

$query="SELECT * FROM LibraryFolders WHERE ".$level[0]." = 'YES'";
Pierre
  • 1,553
  • 12
  • 22
1

I think this should work:

$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} ";

but we need more information: How do you get the array?

hope be helpful

Oscar Gallardo
  • 2,240
  • 3
  • 27
  • 47