0

我正在尝试使用一组五个按钮填充下拉列表框。第一个有效,但其他四个目前还没有。如果环顾四周,但由于缺乏经验,我似乎无法将其放在一起。任何帮助表示赞赏。谢谢你。这是我到目前为止的代码......不完整。

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>
4

1 回答 1

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();
}
于 2013-01-12T05:28:31.273 回答