我从一个列表框中获取值并将其传递给另一个列表框,我让所有东西都使用一个值 $Lid,但现在我需要两个 $Lid 和 $Cid,这是正确的方法吗?
$(document).ready(function()
{
$(".Doggie").change(function()
{
var LocationString = $(this).find(":selected").val();
var CityString = $(this).find(":selected").val();
$.ajax({
type: "POST",
url: "ajax_city.php",
data: {Lid : LocationString, Cid : CityString},
cache: false,
success: function (html) {
$(".Kitty").html(html);
}
});
});
$('.Kitty').live("change",function(){
var LocationString = $(this).find(":selected").val();
var CityString = $(this).find(":selected").val();
$.ajax({
type: "POST",
url: "ajax_area.php",
data: {Lid : LocationString, Cid : CityString},
cache: false,
success: function (html) {
$(".Pig").html(html);
}
});
});
});
</script>
</head>
<body>
<div id="frame1">
<label>Place :</label>
<select name="Doggie" class="Doggie" id="Doggie">
<option selected="selected">--Select Place--</option>
<?php
$sql = mysql_query("SELECT tblLocations.RestID as Lid, tblLocations.CityID as Cid, tblRestaurants.RestName as name
FROM tblRestaurants INNER JOIN tblLocations ON tblRestaurants.RestID = tblLocations.RestID
GROUP BY tblLocations.RestID, tblRestaurants.RestName
ORDER BY tblRestaurants.RestName ASC");
while($row=mysql_fetch_array($sql))
{
echo '<option value="'.$row['Lid'].''.$row['Cid'].'">'.$row['name'].'</option>';
} ?>
</select>
<label>City :</label>
<select name="Kitty" class="Kitty" id="Kitty">
<option selected="selected">--Select City--</option>
</select>
<label>Area: :</label>
<select name="Pig" class="Pig" id="Pig">
<option selected="selected">--Select Area--</option>
</select>
</div>
</body>
</html>
和...
<?php
require ('config.php');
if ($_POST['Lid']) {
$Lid = $_POST['Lid'];
$sql = mysql_query("SELECT tblLocations.RestId as Lid, tblLocations.CityID as Cid, tblCities.CityName as name
FROM tblLocations INNER JOIN tblCities ON tblLocations.CityID = tblCities.CityID
WHERE tblLocations.RestID = $Lid
GROUP BY tblLocations.RestID, tblCities.CityName
ORDER BY tblCities.CityName ASC");
echo '<option selected="selected">--Select City--</option>';
while ($row = mysql_fetch_array($sql)) {
echo '<option value="' . $row['Lid'] . '' . $row['Cid'] . '">' . $row['name'] . '</option>';
}
}
?>
现在它没有返回任何东西,所以我不得不假设它是错误的。谢谢你。