我有三个字段,“首字母,品牌,车系”,如何实现三级联动,服务器端用PHP写。感谢!
服务器负责的数据处理,三级联动效果需要 前端实现。数据量大考虑后台ajax输出,配合js。
谢谢,我已经搞好了!
给你个例子参考
数据库:
表1 phase 学段表
字段
phaseId
phaseName 名字
表2 grade 年级表
字段
phaseId
gradeId
gradeName
表3 subject 学科
字段
gradeId
subjectId
subjectName
--------------------------分割线---------------------------------
/**
* 获取页面查询参数数组
*/
private function getParams(){
$params = array();
$params['pagesize'] = 50;
$params['page'] = !empty($_REQUEST['p']) ? $_REQUEST['p'] : 1;
$params['phase'] = $_REQUEST['phase'];
$params['subject'] = $_REQUEST['subject'];
$params['grade'] = $_REQUEST['grade'];
$params['publisher'] = $_REQUEST['publisher'];
$params['city'] = $_REQUEST['city'];
$params['order'] = empty($_REQUEST['order']) ? '' : $_REQUEST['order'];
$params['excellentState'] = isset($_REQUEST['excellentState']) ? $_REQUEST['excellentState'] : '';
$params['judgeState'] = isset($_REQUEST['judgeState']) ? $_REQUEST['judgeState'] : '';
$params['isDel'] = isset($_REQUEST['isDel']) ? $_REQUEST['isDel'] : '';
$params['report'] = isset($_REQUEST['report']) ? $_REQUEST['report'] : '';
$params['keyword'] = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
$pattern = '/\+|-|&|\||!|\(|\)|\{|\}|\[|\]|\^|"|~|\*|\?|:|\\\\/';
$params['keyword'] = preg_replace($pattern, '', $params['keyword']);
return $params;
}
/**
* 将查询参数数组转化为查询条件数组
* @param array $params Url查询参数数组
*/
private function getConditions($params){
$limit = $params['pagesize'];
$skip = ($params['page']-1) * $limit;
$conditions = array("limit"=>$limit,"skip"=>$skip);
if(!empty($params['phase'])){
$conditions['phase'] = array('eq',$params['phase']);
}
if(!empty($params['subject'])){
$conditions['subject'] = array('eq',$params['subject']);
}
if(!empty($params['grade'])){
$conditions['grade'] = array('eq',$params['grade']);
}
if(!empty($params['publisher'])){
$conditions['book_name'] = array('like','%'.urldecode($_REQUEST['publisherName']).'%');
}
if($params['keyword'] !='' ){
$where['id'] = array('like', '%' . $params['keyword'] . '%');
$where['name'] = array('like','%' . $params['keyword'] . '%');
$where['user_name'] = array('like','%' . $params['keyword'] . '%');
$where['_logic'] = 'or';
$conditions['_complex'] = $where;
}
if($params['judgeState'] != ''){
$conditions['judge_state'] = array('eq',$params['judgeState']);
}
if($params['excellentState'] != ''){
$conditions['excellent_state'] = array('eq',$params['excellentState']);
}
if(!empty($params['order'])){
$conditions['order'] = $params['order'];
}
if($params['isDel'] == ''){
$conditions['is_del'] = array('neq',1);
}else{
$conditions['is_del'] = array('eq',$params['isDel']);
}
if($params['report'] != ''){
if($params['report'] == 0){
$conditions['id'] = array('exp', ' NOT IN (select package_id from ts_match_report where content_type=1) ');
}else{
$conditions['id'] = array('exp',' IN (select package_id from ts_match_report where content_type=1) ');
}
}
$conditions['package_state'] = array('eq',1);
//省级或全国超管可以查看所有
if ($this->adminType == 'country' || $this->adminType == 'province') {
if(!empty($params['city'])){
$conditions['city_id'] = array('eq',$params['city']);
}
} else if($this->adminType == 'city') {
$params['city'] = $this->adminAreaId;
$conditions['city_id'] = array('eq',$params['city']);
}
return $conditions;
}
这个东西很好写吧,建议你还是不要看别人的代码自己去写吧,加强自己的体会。