I’ve looked at all the previous examples but still no dice, and I have a basic php question.
The example is here. I want to be able to click on one table and have the options appear like below:

Explicitly declaring the table name in this code works:
if($_GET['action'] == 'getOptions'){
$category = $_GET['category'];
$query = "SELECT `COLUMN_NAME`
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA`='headfirstjson' AND
**`TABLE_NAME`='AmericanOilProduction'**";
$result = db_connection($query);
//echo $result;
$Options = array();
while ($row = mysql_fetch_array($result)) {
$Options[] = $row;
}
echo json_encode(array("Options" => $Options));
exit;
}
This combination of passing in the variable by AJAX does not:
AJAX:
function getOptions(category){
var category = category.value
$.ajax({
url: "getData.php?action=getOptions",
type: "GET",
dataType:"json",
data: {category:category},
success: function(json){
$.each(json.Options,function(){
var option = "<option>"+this.COLUMN_NAME+"</option>"
$('#options').append(option)
});
}
});
}
PHP:
if($_GET['action'] == 'getOptions'){
**$category = $_GET['category']**;
$query = "SELECT `COLUMN_NAME`
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA`='headfirstjson' AND
`TABLE_NAME`='**.$category.**'";
$result = db_connection($query);
//echo $result;
$Options = array();
while ($row = mysql_fetch_array($result)) {
$Options[] = $row;
}
echo json_encode(array("Options" => $Options));
exit;
}
It would be great if someone could help me out! Thanks.
You are attempting to concatenate
$categorywith the periods surrounding it. The double quotes will expand the variable making the table name ‘.AmericanOilProduction.’. Change the code to look like this removing the concatenation operators. They are not needed here. You should sanitize your input too…