我正在尝试使用一组五个按钮填充下拉列表框。第一个工作,但其他四个没有,至今。如果环顾四周,但由于经验不足,我似乎无法把它放在一起。任何帮助表示赞赏。谢谢。这是我到目前为止的代码......不完整。
mysql_select_db('Mydb');
$place = mysql_query("select * from tblRestaurants order by RestName ASC");
$cuisine = mysql_query("select * from tblCuisine order by CuisineName ASC");
$city = mysql_query("select * from tblCities order by CityName ASC");
$state = mysql_query("select * from tblStates order by StateName ASC");
$zipcode = mysql_query("select * from tblLocations order by ZipCode ASC");
while ($nt= mysql_fetch_assoc($place))
$arrData[] = $nt;
if(isset($_GET["ajax"]))
{
echo json_encode($arrData);
die();
}
?>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function displayPlace()
{
$.getJSON("Four.php?ajax=true", function(data) {
$.each(data, function(index, objRecord) {
var option=document.createElement("option");
option.value=objRecord.RestID;
option.text=objRecord.RestName;
$("#Doggie").append('<option value="' + objRecord.RestID + '">' + objRecord.RestName + '</option>');
});
});
}
function displayCuisine()
{
$.getJSON("Four.php?ajax=true", function(data) {
$.each(data, function(index, objRecord) {
var option=document.createElement("option");
option.value=objRecord.CuisineID;
option.text=objRecord.CuisineName;
$("#Doggie").append('<option value="' + objRecord.CuisineID + '">' + objRecord.CuisineName + '</option>');
});
});
}
</script>
<title>SEARCH</title>
</head>
<body>
<form>
<button type="button" onclick="javascript:displayPlace();">Place</button>
<button type="button" onclick="javascript:displayCuisine();">Cuisine</button>
<button type="button" onclick="javascript:displayCity();" >City</button>
<button type="button" onclick="javascript:displayState();">State</button>
<button type="button" onclick="javascript:displayZipCode();">Area</button>
<br />
<select name="Doggie" id="Doggie"></select>
<br />
</form>
</body>
</html>
答案 0 :(得分:0)
请修改您的PHP代码,我试图用一些示例代码解释这个
并在ajax请求中传递一个附加的case参数,然后它将适用于你
$list['place'] = mysql_query("select * from tblRestaurants order by RestName ASC");
$list['cuisine'] = mysql_query("select * from tblCuisine order by CuisineName ASC");
foreach($list as $key=>$value){
while ($nt = mysql_fetch_assoc($list[$key]))
$list_array[$key] = $nt;
}
if(isset($_GET["ajax"]))
{
switch($_GET['case']){
case 'place':
echo json_encode($list_array['place']);
break;
case 'cuisine':
echo json_encode($list_array['cuisine']);
break;
}
die();
}