主要是想做的向下面这个网站的动态选单
http://www.ecarlink.c...nventory(all years, all makes, all models, go的那个)
主要是他前两个year 与 makes是可以双向
第三个models在选择makes后 还能依据第一个年分筛选
我的资料库如下
car#, yr, mk_nm, model
13345, 2000, toyota, camry
45678, 1999, toyota, corolla
78946, 2005, honda, civic
类似这样
目前我只能做出伪三阶选单 >"<
因为最后一个models没办法抓到第一个years的值
只能依据Makes的值来改变
另外 也没办法依据makes改变year的内容
我是参照这位大哥的文章修改的
http://bbs.mychat.to/reads.php?tid=744737但每次修改后 先不说我写的对不对
网页在几次重新整理后 还是无法正常显示最新的结果
都要关掉网页重开或等好一段时间才行
连if else if else也都只能抓到第一个if
后面的都不跑了
只好弄成两个if 才正常点...囧
以下是我的语法 (head前includes java部分就省略)
主页面
<select name="yr[]" id="yr">
<option value="0">Select Year</option>
<?php
$data = "SELECT yr FROM InventoryList"; $result = mysql_query($data) or die();
while ($row = mysql_fetch_array($result)) {echo '<option value="'.$row["yr"].'">'.$row["yr"].'</option>'; }
?>
</select>
<select name="make[]" id="mk_nm">
<option value="">All Makes</option>
<?php
$data = "SELECT mk_nm FROM InventoryList"; $result = mysql_query($data) or die();
while ($row = mysql_fetch_array($result)) {echo '<option value="'.$row["mk_nm"].'">'.$row["mk_nm"].'</option>'; }
?>
</select>
<script type="text/javascript">
jQuery(document).ready(function(){ $('#mk_nm').cascade('#yr', { ajax: {type: "GET", url: 'action3.php', data: { act: 'first', val: $('#yr').val() } },
template: function(item) { return "<option value='" + item.Value + "'>" + item.Text + "</option>"; },
match: function(selectedValue) { return this.When == selectedValue; } });});
</script>
<select name="model[]" id="model">
<option value="">Select Makes</option>
</select>
<script type="text/javascript">
jQuery(document).ready(function(){ $('#model').cascade('#mk_nm', { ajax: {type: "GET", url: 'action3.php', data: { act: 'second', val: $('#mk_nm').val() } },
template: function(item) { return "<option value='" + item.Value + "'>" + item.Text + "</option>"; },
match: function(selectedValue) { return this.When == selectedValue; } });
});
</script>
-------------------------------------------
action页面
if (isset($_GET['act'])) { $action = $_GET['act'];}
if (isset($_GET['val'])) { $parentId = $_GET['val']; }
switch ($action) {
case 'first':
$list = '[{\'When\':\'' . $parentId . '\',\'Value\':\'\',\'Text\':\'Select Make\'},';
if ($parentId == 0) { $query = "SELECT mk_nm FROM InventoryList"; }
if ($parentId != 0) { $query = "SELECT mk_nm FROM InventoryList WHERE yr = '".$parentId."' ORDER BY mk_nm ASC"; }
$result = mysql_query($query) or die();
while ($row = mysql_fetch_array($result)) { $list .= '{\'When\':\'' . $parentId . '\',\'Value\':\'' . $row["mk_nm"] . '\',\'Text\':\'' . $row["mk_nm"] . '\'},';}
break;
case 'second':
$list = '[{\'When\':\'' . $parentId . '\',\'Value\':\'\',\'Text\':\'Select Model\'},';
$query = "SELECT model FROM InventoryList WHERE mk_nm = '".$parentId."' ORDER BY model ASC";
$result = mysql_query($query) or die();
while ($row = mysql_fetch_array($result)) { $list .= '{\'When\':\'' . $parentId . '\',\'Value\':\'' . $row["model"] . '\',\'Text\':\'' . $row["model"] . '\'},';}
break;
}
$list .= ']';
echo $list;
烦请请各位高手指点建议
感激不尽>"<