PHP二级菜单通过一级菜单选取的数据生成二级菜单内符合的数据
请看图如图,我需要在选择了分校名后,主教老师的选择下拉框内只出现该校的,选择教师后,再出现教师所教的科目。代码贴上,目前只能实现各选个的,没办法关联起来,数据库里各个表,...
请看图
如图,我需要在选择了分校名后,主教老师的选择下拉框内只出现该校的,选择教师后,再出现教师所教的科目。
代码贴上,目前只能实现各选个的,没办法关联起来,数据库里各个表,我都建了关联的字段。
function.php文件
//获取分校名下拉菜单function getCategorySelect($tablename,$select_id=0,$id = 0,$level = 0){ global $db; $category_arr = $db->getList (get_sql( "SELECT * FROM {pre}$tablename WHERE fid = " . $id . " order by rank" )); for($lev = 0; $lev < $level * 2 - 1; $lev ++) { $level_nbsp .= " "; } if ($level++) $level_nbsp .= "┝"; foreach ( $category_arr as $category ) { $id = $category ['id']; $fid = $category ['fid']; $name = $category ['name']; $selected = $select_id==$id?'selected':''; echo "<option value=\"".$id."\" ".$selected.">".$level_nbsp . " " . $name."</option>\n"; getCategorySelect ($tablename,$select_id, $id, $level ); }}
//获取教师名下拉菜单function getCatesecondSelect($tablename,$select_id=0,$id = 0,$level = 0){ global $db; $category_arr = $db->getList (get_sql( "SELECT * FROM {pre}$tablename WHERE fid = " . $id . " order by rank" )); for($lev = 0; $lev < $level * 2 - 1; $lev ++) { $level_nbsp .= " "; } if ($level++) $level_nbsp .= "┝"; foreach ( $category_arr as $category ) { $id = $category ['id']; $fid = $category ['fid']; $name = $category ['name']; $selected = $select_id==$id?'selected':''; echo "<option value=\"".$id."\" ".$selected.">".$level_nbsp . " " . $name."</option>\n"; getCatesecondSelect ($tablename,$select_id, $id, $level ); }}
前台页面可以正常提取数据,就是请大家帮忙看看,这里要怎么修改下,达到前台调用的时候,值已经筛选。。
前台页面customer_action.php
<select name="area" id="area">
<option>选择分校</option>
<?php getCategorySelect("area",$fid); ?>
</select>
----------------------------------------------------
<select name="industry" id="industry">
<option>选择教师</option>
<?php getCatesecondSelect("industry",$id); ?>
</select> 展开
如图,我需要在选择了分校名后,主教老师的选择下拉框内只出现该校的,选择教师后,再出现教师所教的科目。
代码贴上,目前只能实现各选个的,没办法关联起来,数据库里各个表,我都建了关联的字段。
function.php文件
//获取分校名下拉菜单function getCategorySelect($tablename,$select_id=0,$id = 0,$level = 0){ global $db; $category_arr = $db->getList (get_sql( "SELECT * FROM {pre}$tablename WHERE fid = " . $id . " order by rank" )); for($lev = 0; $lev < $level * 2 - 1; $lev ++) { $level_nbsp .= " "; } if ($level++) $level_nbsp .= "┝"; foreach ( $category_arr as $category ) { $id = $category ['id']; $fid = $category ['fid']; $name = $category ['name']; $selected = $select_id==$id?'selected':''; echo "<option value=\"".$id."\" ".$selected.">".$level_nbsp . " " . $name."</option>\n"; getCategorySelect ($tablename,$select_id, $id, $level ); }}
//获取教师名下拉菜单function getCatesecondSelect($tablename,$select_id=0,$id = 0,$level = 0){ global $db; $category_arr = $db->getList (get_sql( "SELECT * FROM {pre}$tablename WHERE fid = " . $id . " order by rank" )); for($lev = 0; $lev < $level * 2 - 1; $lev ++) { $level_nbsp .= " "; } if ($level++) $level_nbsp .= "┝"; foreach ( $category_arr as $category ) { $id = $category ['id']; $fid = $category ['fid']; $name = $category ['name']; $selected = $select_id==$id?'selected':''; echo "<option value=\"".$id."\" ".$selected.">".$level_nbsp . " " . $name."</option>\n"; getCatesecondSelect ($tablename,$select_id, $id, $level ); }}
前台页面可以正常提取数据,就是请大家帮忙看看,这里要怎么修改下,达到前台调用的时候,值已经筛选。。
前台页面customer_action.php
<select name="area" id="area">
<option>选择分校</option>
<?php getCategorySelect("area",$fid); ?>
</select>
----------------------------------------------------
<select name="industry" id="industry">
<option>选择教师</option>
<?php getCatesecondSelect("industry",$id); ?>
</select> 展开
3个回答
展开全部
可以采用Jquery ajax请求
<select name="area" id="area">
<option>选择分校</option>
<?php getCategorySelect("area",$fid); ?>
</select>
把分校的值ajax传到后台处理,拿到 选择教师的数据,添加到 select 上
更多追问追答
追问
具体怎么写,麻烦了。。不会很会。。
追答
稍等,我帮你写下
<script type="text/javascript" src="jquery.min.js"></script>
<!--选择分校-->
<select name="area" id="area">
<option>选择分校</option>
<?php getCategorySelect("area",$fid); ?>
</select>
<!--选择教师-->
<select name="industry" id="industry">
<option>选择教师</option>
<?php getCatesecondSelect("industry",$id); ?>
</select>
<script type="text/javascript">
$(function(){
$('#area').change(function(event) {
var value = $(this).val();
$.ajax({
url: '/path/to/file',//这个是你拿教师数据的URL地址,比如本页
type: 'POST', //采用POST的提交
dataType: 'html',//返回格式为html
data: {area_id: value,type: 'ajax'},//post的数据
session:function(data){//处理完成后操作
$('industry').html(data);
}
});
});
})
</script>
php处理
<?php
if (isset($_POST['ajax'])) {
$id = intval($_POST['area_id']);
echo getCatesecondSelect("industry",$id);
exit();
}
?>
展开全部
一般这种情况都是判断 select框的 onchange 事件,然后把一级菜单的值ajax请求数据库,返回的数据放在二级菜单里面……
追问
具体怎么写,麻烦了。。不会很会。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
echo "<option value=$id $selected>$level_nbsp$name</option>\n";
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询