0
我已經在這裏得到了一些幫助,但不幸的是,我仍然在級聯下拉上苦苦掙扎。我需要下面的<select>
根據#city
,上面的一個<select>
框的選擇進行更新。jQuery級聯下拉問題
我的代碼中是否有任何明顯的錯誤?
HTML/jQuery的:
<select name="club" class="dropdown" id="club">
<script>
$('#city').change(function(){
var $club = $('#club');
$club.find('option:not([value="default"])').remove(); //Remove previous items
$.getJSON('getClubs.php', {city:$(this).val()}, function(clubs){
$.each(clubs, function(index, city){
$club.append('<option value="'+row[0]+'">'+row[1]+'</option>');
});
});
});
</script>
</select>
PHP(getClubs.php):
<?php
date_default_timezone_set('Europe/London');
$day = date("l");
$time = date("G");
if ($time >= 21) {
$day = date('l', strtotime($day .' +1 day'));
}
$city = $_POST['city'];
if ($day == Monday) {
$query = "SELECT name FROM nights WHERE city = '$city' ORDER BY FIELD(day, 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY')";
}
else if ($day == Tuesday) {
$query = "SELECT name FROM nights WHERE city = '$city' ORDER BY FIELD(day, 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY', 'MONDAY')";
}
else if ($day == Wednesday) {
$query = "SELECT name FROM nights WHERE city = '$city' ORDER BY FIELD(day, 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY', 'MONDAY', 'TUESDAY')";
}
else if ($day == Thursday) {
$query = "SELECT name FROM nights WHERE city = '$city' ORDER BY FIELD(day, 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY')";
}
else if ($day == Friday) {
$query = "SELECT name FROM nights WHERE city = '$city' ORDER BY FIELD(day, 'FRIDAY', 'SATURDAY', 'SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY')";
}
else if ($day == Saturday) {
$query = "SELECT name FROM nights WHERE city = '$city' ORDER BY FIELD(day, 'SATURDAY', 'SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY')";
}
else if ($day == Sunday) {
$query = "SELECT name FROM nights WHERE city = '$city' ORDER BY FIELD(day, 'SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY')";
}
$result = mysql_query($query);
$items = array();
if($result && mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result)) {
$items[] = array($row[0], $row[1]);
}
}
mysql_close();
// convert into JSON format and print
echo json_encode($items);
?>
哪兒了該行變量來自? –
我不確定,但填寫第一個
如何在jQuery代碼中嘗試使用[0]和[1]來代替行[0]和行[1] –