首页 新闻 搜索 专区 学院

用php如何实现这个三级联动

0
悬赏园豆:20 [已解决问题] 解决于 2016-04-29 08:22

我有三个字段,“首字母,品牌,车系”,如何实现三级联动,服务器端用PHP写。感谢!

沉默为金的主页 沉默为金 | 初学一级 | 园豆:173
提问于:2016-04-21 15:04
< >
分享
最佳答案
0

服务器负责的数据处理,三级联动效果需要 前端实现。数据量大考虑后台ajax输出,配合js。

收获园豆:20
慧☆星 | 大侠五级 |园豆:5533 | 2016-04-28 17:53

谢谢,我已经搞好了!

沉默为金 | 园豆:173 (初学一级) | 2016-04-29 08:21
其他回答(2)
0

给你个例子参考

数据库:
表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;
}

AnonymouL | 园豆:1769 (小虾三级) | 2016-04-22 10:56
0

这个东西很好写吧,建议你还是不要看别人的代码自己去写吧,加强自己的体会。

斯拉克 | 园豆:223 (菜鸟二级) | 2016-04-22 13:27
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册