-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcarBrand.php
85 lines (73 loc) · 2.9 KB
/
carBrand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
//az_inserted
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
//处理AJAX请求
$act = !empty($_GET['act']) ? $_GET['act'] : '';
if ($act == 'query_sub_car_types')
{
$pageId=!empty($_GET['pageId']) ? $_GET['pageId'] : '1';
$catId=$_GET['cat_id'];
$catName=$_GET['cat_name'];
$result['cat_id']=$catId;
$resultIndex = 0;
$carYears = '';
$capacities='';
$car_types = getCategorySelection($catId);
foreach($car_types as $one_car_type){
$car_types_2 = getCategorySelection($one_car_type['cat_id']);//年款
foreach($car_types_2 as $one_car_type_2){
if(!strstr($carYears, $one_car_type_2['cat_name'])){
$carYears=$carYears.",".$one_car_type_2['cat_name'];
}
$car_types_3 = getCategorySelection($one_car_type_2['cat_id']);//排量
foreach($car_types_3 as $one_car_type_3){
if(!strstr($capacities, $one_car_type_3['cat_name'])){
$capacities=$capacities.",".$one_car_type_3['cat_name'];
}
$car_types_4 = getCategorySelection($one_car_type_3['cat_id']);
if(count($car_types_4) == 0){
if($one_car_type['cat_name'] == "null_type"){
$retTypes[$resultIndex]['name']=$catName.' '.$one_car_type_2['cat_name'].' '.$one_car_type_3['cat_name'];
}else{
$retTypes[$resultIndex]['name']=$catName.' '.$one_car_type['cat_name'].' '.$one_car_type_2['cat_name'].' '.$one_car_type_3['cat_name'];
}
$retTypes[$resultIndex]['cat_id']=$one_car_type_3['cat_id'];
$resultIndex++;
}else{
foreach($car_types_4 as $one_car_type_4){
if($one_car_type['cat_name'] == "null_type"){
$retTypes[$resultIndex]['name']=$catName.' '.$one_car_type_2['cat_name'].' '.$one_car_type_3['cat_name'].' '.$one_car_type_4['cat_name'];
}else{
$retTypes[$resultIndex]['name']=$catName.' '.$one_car_type['cat_name'].' '.$one_car_type_2['cat_name'].' '.$one_car_type_3['cat_name'].' '.$one_car_type_4['cat_name'];
}
$retTypes[$resultIndex]['cat_id']=$one_car_type_4['cat_id'];
$resultIndex++;
}
}
}
}
}
$result['car_types']=$retTypes;
$result['carYears']=$carYears;
$result['capacities']=$capacities;
include_once('includes/cls_json.php');
$json = new JSON;
die($json->encode($result));
}
//完成AJAX请求的处理
assign_template();
$my_sql = "SELECT cat_name, cat_id FROM ecs_category WHERE parent_id = 1 ORDER BY CONVERT( cat_name USING gbk )";
$all_car_brands = $GLOBALS['db']->getAll($my_sql);
for($i=0; $i<count($all_car_brands); $i++){
$one_sql = "SELECT cat_name, cat_id FROM ecs_category WHERE parent_id = ".$all_car_brands[$i]['cat_id'];
$car_types = $GLOBALS['db']->getAll($one_sql);
$all_car_brands[$i]['car_types']=$car_types;
}
//print_r($all_car_brands);
$smarty->assign('all_car_brands', $all_car_brands);
$smarty->display('carBrand.dwt');
function getCategorySelection($_cat_id){
return $GLOBALS['db']->getAll("SELECT cat_name, cat_id FROM ecs_category WHERE parent_id = ".$_cat_id);
}
?>