我已经查看了所有先前的示例,但仍然没有骰子,并且我有一个基本的 php 问题。
例子在这里。我希望能够单击一个表并让选项显示如下:
在此代码中显式声明表名有效:
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;
}
这种通过 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;
}
如果有人可以帮助我,那就太好了!谢谢。