美好的一天。请帮我。我创建了一个选择:
<select id="type" multiple>
<option value="63">1963</option>
<option value="64">1964</option>
<option value="65">1965</option>
<option value="66">1966</option>
<option value="67">1967</option>
<option value="68">1968</option>
<option value="69">1969</option>
<option value="70">1970</option>
<option value="71">1971</option>
<option value="72">1972</option>
<option value="73">1973</option>
<option value="74">1974</option>
<option value="75">1975</option>
<option value="76">1976</option>
<option value="77">1977</option>
<option value="78">1978</option>
<option value="79">1979</option>
<option value="80">1980</option>
<option value="81">1981</option>
<option value="82">1982</option>
<option value="83">1983</option>
<option value="84">1984</option>
<option value="85">1985</option>
<option value="86">1986</option>
<option value="87">1987</option>
<option value="89">1989</option>
<option value="91">1991</option>
</select>
</td>
<td>
<select id="kind" disabled multiple>
<option></option>
</select>
</td>
<td>
<select id="category" onchange="showhideBlocks(this.value)" disabled multiple>
<option></option>
</select>
我的PHP代码:
<?php
$types = array(
63 => array(
1 => 'Неизвестный'
),
64 => array(
1 => 'Неизвестный'
),
65 => array(
1 => 'Неизвестный'
),
66 => array(
1 => 'Alpha Industries, Inc.',
2 => 'John Ownbey Company, Inc.',
3 => 'Southern Athletic, Inc.',
4 => 'Rolane Sportswear, Inc.',
5 => 'Hamilton Tailoring',
6 => 'Hirsch Tyler Co.',
7 => 'Freeland Shirt Co.',
8 => 'Atlantic Highlands Mfg. Co.',
9 => 'Marcie Dale Inc.',
10 => 'AG Outerwear Corp.'
),
67 => array(
1 => 'SAF-T-BAK Inc.',
2 => 'Addleman Mfg. Co.',
3 => 'SGS Mfg. Co.',
4 => 'Kent Sportswear Inc.',
5 => 'Harrigan BL Inc.',
6 => 'Edwards Ralph Sportswear Inc.',
7 => 'Dale Fashions Inc.',
8 => 'Simon & Mogilner',
9 => 'Crescent Sportswear Inc.',
10 => 'Neptune Raincoat Co. Inc.',
11 => 'Days Tailord Clothing Inc.',
12 => 'Robitsher Schneider Co.',
13 => 'Cherry Tree Suedes',
14 => 'Bilamco Inc.',
15 => 'Chief Apparel Inc.',
16 => 'Rolane Sportswear, Inc.',
17 => 'Alpha Industries, Inc.',
18 => 'Allen Overall Co., Inc.',
19 => 'So-Sew Styles, Inc.',
20 => 'Flint Sportswear',
21 => 'New England Industries Inc.',
22 => 'Provisor Sportswear',
23 => 'Ringer Co.',
24 => 'Atomic Sportswear',
25 => 'Milford Mfg. Co.',
26 => 'Lustberg, Nast & Co. Inc.',
27 => 'Leco Industries Inc.',
28 => 'неизвестный',
29 => 'Dan Jac Sportswear',
30 => 'Vista Corp.',
31 => 'Sunset Sportswear Inc.'
),
68 => array(
1 => 'Defense Personnel Support Center',
2 => 'Apparel Corp. Of America',
3 => 'John Ownbey Company, Inc.',
4 => 'So-Sew Styles, Inc.',
5 => 'Rolane Sportswear, Inc.',
6 => 'Bonham Manufacturing Co., Inc.',
7 => 'Alpha Industries, Inc.',
8 => 'Sportsmaster Inc.',
9 => 'Mason & Hughes Inc.',
10 => 'Appleman Mfg. Co.',
11 => 'Allen Overall Co., Inc.'
),
69 => array(
1 => 'Rolane Sportswear, Inc.',
2 => 'Apparel Corp. Of America',
3 => 'Alpha Industries, Inc.',
4 => 'So-Sew Styles, Inc.',
5 => 'Sportsmaster Inc.',
6 => 'Allen Overall Co., Inc.',
7 => 'John Ownbey Company, Inc.'
),
70 => array(
1 => 'John Ownbey Company, Inc.',
2 => 'Alpha Industries, Inc.',
3 => 'Rolane Sportswear, Inc.',
4 => 'So-Sew Styles, Inc.',
5 => 'Allen Overall Co., Inc.',
6 => 'Southern Athletic, Inc.'
),
71 => array(
1 => 'Alpha Industries, Inc.',
2 => 'John Ownbey Company, Inc.',
3 => 'So-Sew Styles, Inc.',
4 => 'Rolane Sportswear, Inc.'
),
72 => array(
1 => 'John Ownbey Company, Inc.',
2 => 'So-Sew Styles, Inc.',
3 => 'Alpha Industries, Inc.',
4 => 'Rolane Sportswear, Inc.'
),
73 => array(
1 => 'So-Sew Styles, Inc.',
2 => 'Alpha Industries, Inc.',
3 => 'John Ownbey Company, Inc.'
),
74 => array(
1 => 'Defense Personnel Support Center',
2 => 'So-Sew Styles, Inc.',
3 => 'Alpha Industries, Inc.',
4 => 'John Ownbey Company, Inc.'
),
75 => array(
1 => 'So-Sew Styles, Inc.',
2 => 'Alpha Industries, Inc.',
3 => 'Cherokee Industries, Inc.'
),
76 => array(
1 => 'Defense Personnel Support Center',
2 => 'Winfield Manufacturing Co., Inc.',
3 => 'Alpha Industries, Inc.',
4 => 'So-Sew Styles, Inc.',
5 => 'John Ownbey Company, Inc.'
),
77 => array(
1 => 'Defense Personnel Support Center',
2 => 'Alpha Industries, Inc.',
3 => 'So-Sew Styles, Inc.',
4 => 'John Ownbey Company, Inc.'
),
78 => array(
1 => 'So-Sew Styles, Inc.',
2 => 'Alpha Industries, Inc.',
3 => 'John Ownbey Company, Inc.',
4 => 'Issachar Manufacturing Co., Inc.'
),
79 => array(
1 => 'Defense Personnel Support Center',
2 => 'So-Sew Styles, Inc.',
3 => 'Alpha Industries, Inc.'
),
80 => array(
1 => 'Issachar Manufacturing Co., Inc.',
2 => 'John Ownbey Company, Inc.',
3 => 'Alpha Industries, Inc.',
4 => 'So-Sew Styles, Inc.',
5 => 'Golden Mfg. Co., Inc.'
),
81 => array(
1 => 'Defense Personnel Support Center',
2 => 'So-Sew Styles, Inc.',
3 => 'Alpha Industries, Inc.',
4 => 'Golden Mfg. Co., Inc.',
5 => 'John Ownbey Company, Inc.',
6 => 'Dakota Industries, Inc.',
7 => 'Winfield Manufacturing Co., Inc.'
),
82 => array(
1 => 'Defense Personnel Support Center',
2 => 'Golden Mfg. Co., Inc.',
3 => 'Alpha Industries, Inc.',
4 => 'So-Sew Styles, Inc.',
5 => 'Vanderbilt Shirt Co., Inc.'
),
83 => array(
1 => 'Defense Personnel Support Center',
2 => 'John Ownbey Company, Inc.'
),
84 => array(
1 => 'Defense Personnel Support Center',
2 => 'Golden Mfg. Co., Inc.'
),
85 => array(
1 => 'Golden Mfg. Co., Inc.'
),
86 => array(
1 => 'So-Sew Styles, Inc.'
),
87 => array(
1 => 'So-Sew Styles, Inc.'
),
89 => array(
1 => 'So-Sew Styles, Inc.'
),
91 => array(
1 => 'American Apparel, Inc.'
),
);
$kinds = array(
63 => array(
1 => array(
T635 => 'Т-63-5'
),
),
64 => array(
1 => array(
T635 => 'Т-63-5'
),
),
65 => array(
1 => array(
DSA18666 => 'DSA-1-8666'
),
),
66 => array(
1 => array(
DSA100817 => 'DSA 100-817',
DSA1001690 => 'DSA 100-1690',
DSA1003378 => 'DSA 100-3378'
),
2 => array(
DSA1001691 => 'DSA 100-1691'
),
3 => array(
DSA1001928 => 'DSA 100-1928',
DSA1002365 => 'DSA 100-2365'
),
4 => array(
DSA1002366 => 'DSA 100-2366',
DSA1003255 => 'DSA 100-3255'
),
5 => array(
DSA1002936 => 'DSA 100-2936'
),
6 => array(
DSA1003491 => 'DSA 100-3491'
),
7 => array(
DSA1004542 => 'DSA 100-4542'
),
8 => array(
DSA1004544 => 'DSA 100-4544'
),
9 => array(
DSA1004899 => 'DSA 100-4899'
),
10 => array(
DSA1005005 => 'DSA 100-5005'
),
),
67 => array(
1 => array(
DSA10067C0107 => 'DSA 100-67-C-0107'
),
2 => array(
DSA10067C0115 => 'DSA 100-67-C-0115'
),
3 => array(
DSA10067C0116 => 'DSA 100-67-C-0116'
),
4 => array(
DSA10067C0117 => 'DSA 100-67-C-0117'
),
5 => array(
DSA10067C0125 => 'DSA 100-67-C-0125'
),
6 => array(
DSA10067C0126 => 'DSA 100-67-C-0126'
),
7 => array(
DSA10067C0159 => 'DSA 100-67-C-0159'
),
8 => array(
DSA10067C0165 => 'DSA 100-67-C-0165'
),
9 => array(
DSA10067C0183 => 'DSA 100-67-C-0183',
DSA10067C0759 => 'DSA 100-67-C-0759'
),
10 => array(
DSA10067C0186 => 'DSA 100-67-C-0186'
),
11 => array(
DSA10067C0195 => 'DSA 100-67-C-0195'
),
12 => array(
DSA10067C0213 => 'DSA 100-67-C-0213'
),
13 => array(
DSA10067C0217 => 'DSA 100-67-C-0217'
),
14 => array(
DSA10067C0221 => 'DSA 100-67-C-0221'
),
15 => array(
DSA10067C0249 => 'DSA 100-67-C-0249',
DSA10067C0706 => 'DSA 100-67-C-0706'
),
16 => array(
DSA10067C3536 => 'DSA 100-67-C-3536'
),
17 => array(
DSA10067C3537 => 'DSA 100-67-C-3537',
DSA10067C4097 => 'DSA 100-67-C-4097',
DSA10067C4426 => 'DSA 100-67-C-4426'
),
18 => array(
DSA10067C4425 => 'DSA 100-67-C-4425'
),
19 => array(
DSA10067C4540 => 'DSA 100-67-C-4540'
),
20 => array(
DSA10067C0640 => 'DSA 100-67-C-0640'
),
21 => array(
DSA10067C0641 => 'DSA 100-67-C-0641'
),
22 => array(
DSA10067C0648 => 'DSA 100-67-C-0648'
),
23 => array(
DSA10067C0653 => 'DSA 100-67-C-0653'
),
24 => array(
DSA10067C0655 => 'DSA 100-67-C-0655'
),
25 => array(
DSA10067C0669 => 'DSA 100-67-C-0669'
),
26 => array(
DSA10067C0683 => 'DSA 100-67-C-0683'
),
27 => array(
DSA10067C0692 => 'DSA 100-67-C-0692'
),
28 => array(
DSA10067C0746 => 'DSA 100-67-C-0746'
),
29 => array(
DSA10067C0747 => 'DSA 100-67-C-0747'
),
30 => array(
DSA10067C0767 => 'DSA 100-67-C-0767'
),
31 => array(
DSA10067C0778 => 'DSA 100-67-C-0778'
),
),
68 => array(
1 => array(
8025 => '8025*',
8118 => '8118*'
),
2 => array(
DSA10068C0411 => 'DSA 100-68-C-0411',
DSA10068C2016 => 'DSA 100-68-C-2016'
),
3 => array(
DSA10068C0471 => 'DSA 100-68-C-0471'
),
4 => array(
DSA10068C0472 => 'DSA 100-68-C-0472',
DSA10068C2019 => 'DSA 100-68-C-2019'
),
5 => array(
DSA10068C0967 => 'DSA 100-68-C-0967'
),
6 => array(
DSA10068C0968 => 'DSA 100-68-C-0968'
),
7 => array(
DSA10068C1044 => 'DSA 100-68-C-1044',
DSA10068C1974 => 'DSA 100-68-C-1974'
),
8 => array(
DSA10068C2017 => 'DSA 100-68-C-2017',
DSA10068C2171 => 'DSA 100-68-C-2171'
),
9 => array(
DSA10068C2018 => 'DSA 100-68-C-2018'
),
10 => array(
DSA10068C2372 => 'DSA 100-68-C-2372'
),
11 => array(
DSA10068C2373 => 'DSA 100-68-C-2373'
),
),
69 => array(
1 => array(
DSA10069C0760 => 'DSA 100-69-C-0760',
DSA10069C2482 => 'DSA 100-69-C-2482'
),
2 => array(
DSA10069C0761 => 'DSA 100-69-C-0761'
),
3 => array(
DSA10069C0762 => 'DSA 100-69-C-0762',
DSA10069C2317 => 'DSA 100-69-C-2317'
),
4 => array(
DSA10069C0818 => 'DSA 100-69-C-0818',
DSA10069C2483 => 'DSA 100-69-C-2483'
),
5 => array(
DSA10069C1006 => 'DSA 100-69-C-1006',
DSA10069C2484 => 'DSA 100-69-C-2484'
),
6 => array(
DSA10069C1086 => 'DSA 100-69-C-1086'
),
7 => array(
DSA10069C1087 => 'DSA 100-69-C-1087'
),
),
70 => array(
1 => array(
DSA10070C0525 => 'DSA 100-70-C-0525',
DSA10070C0613 => 'DSA 100-70-C-0613'
),
2 => array(
DSA10070C0606 => 'DSA 100-70-C-0606'
),
3 => array(
DSA10070C0607 => 'DSA 100-70-C-0607'
),
4 => array(
DSA10070C0644 => 'DSA 100-70-C-0644'
),
5 => array(
DSA10070C0645 => 'DSA 100-70-C-0645'
),
6 => array(
DSA10070C0646 => 'DSA 100-70-C-0646'
),
),
71 => array(
1 => array(
DSA10071C0180 => 'DSA 100-71-C-0180',
DSA10071C1337 => 'DSA 100-71-C-1337'
),
2 => array(
DSA10071C0181 => 'DSA 100-71-C-0181'
),
3 => array(
DSA10071C0201 => 'DSA 100-71-C-0201'
),
4 => array(
DSA10071C0246 => 'DSA 100-71-C-0246'
),
),
72 => array(
1 => array(
DSA10072C0130 => 'DSA 100-72-C-0130',
DSA10072C0702 => 'DSA 100-72-C-0702',
DSA10072C1203 => 'DSA 100-72-C-1203',
DSA10072C1733 => 'DSA 100-72-C-1733'
),
2 => array(
DSA10072C0131 => 'DSA 100-72-C-0131',
DSA10072C1091 => 'DSA 100-72-C-1091',
DSA10072C1732 => 'DSA 100-72-C-1732'
),
3 => array(
DSA10072C0132 => 'DSA 100-72-C-0132',
DSA10072C0703 => 'DSA 100-72-C-0703',
DSA10072C1202 => 'DSA 100-72-C-1202',
DSA10072C1666 => 'DSA 100-72-C-1666'
),
4 => array(
DSA10072C0779 => 'DSA 100-72-C-0779'
),
),
73 => array(
1 => array(
DSA10073C0358 => 'DSA 100-73-C-0358',
DSA10073C1019 => 'DSA 100-73-C-1019'
),
2 => array(
DSA10073C0856 => 'DSA 100-73-C-0856'
),
3 => array(
DSA10073C1022 => 'DSA 100-73-C-1022'
),
),
74 => array(
1 => array(
801674 => '8016-74'
),
2 => array(
DSA10074C0129 => 'DSA 100-74-C-0129',
DSA10074C1416 => 'DSA 100-74-C-1416'
),
3 => array(
DSA10074C0130 => 'DSA 100-74-C-0130',
DSA10074C1417 => 'DSA 100-74-C-1417'
),
4 => array(
DSA10074C0354 => 'DSA 100-74-C-0354',
DSA10074C1415 => 'DSA 100-74-C-1415'
),
),
75 => array(
1 => array(
DSA10075C0510 => 'DSA 100-75-C-0510'
),
2 => array(
DSA10075C0511 => 'DSA 100-75-C-0511',
DSA10075C1376 => 'DSA 100-75-C-1376'
),
3 => array(
DSA10075C1200 => 'DSA 100-75-C-1200'
),
),
76 => array(
1 => array(
605376 => '6053-76',
902376 => '9023-76'
),
2 => array(
DSA10076C0605 => 'DSA 100-76-C-0605'
),
3 => array(
DSA10076C0739 => 'DSA 100-76-C-0739',
DSA10076C1003 => 'DSA 100-76-C-1003'
),
4 => array(
DSA10076C0889 => 'DSA 100-76-C-0889',
DSA10076C1084 => 'DSA 100-76-C-1084'
),
5 => array(
DSA10076C1083 => 'DSA 100-76-C-1083'
),
),
77 => array(
1 => array(
711677 => '7116-77',
715077 => '7150-77',
727077 => '7270-77'
),
2 => array(
DSA10077C0684 => 'DSA 100-77-C-0684',
DSA10077C1387 => 'DSA 100-77-C-1387'
),
3 => array(
DSA10077C0796 => 'DSA 100-77-C-0796',
DSA10077C1386 => 'DSA 100-77-C-1386'
),
4 => array(
DSA10077C1385 => 'DSA 100-77-C-1385'
),
),
78 => array(
1 => array(
DLA10078C0378 => 'DLA 100-78-C-0378',
DLA10078C1219 => 'DLA 100-78-C-1219'
),
2 => array(
DLA10078C0379 => 'DLA 100-78-C-0379',
DLA10078C1098 => 'DLA 100-78-C-1098'
),
3 => array(
DLA10078C0528 => 'DLA 100-78-C-0528',
DLA10078C1097 => 'DLA 100-78-C-1097'
),
4 => array(
DLA10078C1205 => 'DLA 100-78-C-1205'
),
),
79 => array(
1 => array(
913679 => '9136-79'
),
2 => array(
DLA10079C2904 => 'DLA 100-79-C-2904'
),
3 => array(
DLA10079C2905 => 'DLA 100-79-C-2905'
),
),
80 => array(
1 => array(
DLA10080C2462 => 'DLA 100-80-C-2462'
),
2 => array(
DLA10080C2529 => 'DLA 100-80-C-2529',
DLA10080C3301 => 'DLA 100-80-C-3301'
),
3 => array(
DLA10080C2530 => 'DLA 100-80-C-2530',
DLA10080C3302 => 'DLA 100-80-C-3302'
),
4 => array(
DLA10080C2676 => 'DLA 100-80-C-2676'
),
5 => array(
DLA10080C3303 => 'DLA 100-80-C-3303'
),
),
81 => array(
1 => array(
711081 => '7110-81'
),
2 => array(
DLA10081C2335 => 'DLA 100-81-C-2335',
DLA10081C3070 => 'DLA 100-81-C-3070'
),
3 => array(
DLA10081C2336 => 'DLA 100-81-C-2336',
DLA10081C3071 => 'DLA 100-81-C-3071',
DLA10081C3463 => 'DLA 100-81-C-3463'
),
4 => array(
DLA10081C2337 => 'DLA 100-81-C-2337'
),
5 => array(
DLA10081C2485 => 'DLA 100-81-C-2485',
DLA10081C3464 => 'DLA 100-81-C-3464'
),
6 => array(
DLA10081C2501 => 'DLA 100-81-C-2501'
),
7 => array(
DLA10081C3462 => 'DLA 100-81-C-3462'
),
),
82 => array(
1 => array(
804882 => '8048-82'
),
2 => array(
DLA10082C0574 => 'DLA 100-82-C-0574'
),
3 => array(
DLA10082C0575 => 'DLA 100-82-C-0575'
),
4 => array(
DLA10082C0576 => 'DLA 100-82-C-0576'
),
5 => array(
DLA10082C0577 => 'DLA 100-82-C-0577'
),
),
83 => array(
1 => array(
903183 => '9031-83'
),
2 => array(
DLA10083C0655 => 'DLA 100-83-C-0655'
),
),
84 => array(
1 => array(
617484 => '6174-84',
913184 => '9131-84'
),
2 => array(
DLA10084C0292 => 'DLA 100-84-C-0292'
),
),
85 => array(
1 => array(
DLA10085C0379 => 'DLA 100-85-C-0379'
),
),
86 => array(
1 => array(
DLA10086C0442 => 'DLA 100-86-C-0442'
),
),
87 => array(
1 => array(
DLA10087C0591 => 'DLA 100-87-C-0591'
),
),
89 => array(
1 => array(
DLA10089C0360 => 'DLA 100-89-C-0360'
),
),
91 => array(
1 => array(
DLA10091C0450 => 'DLA 100-91-C-0450'
)
)
);
// Проверяем наличие переменной, которая укажет данному сценарию какие именно данные нужны
if (!isset($_POST['query']) || !$_POST['query']) {
exit("Нет данных определяющих тип запроса");
}
else {
// Сохраняем строку запроса данных в отдельной переменной
$query = trim($_POST['query']); // Очищаем от лишних пробелов
// Определяем тип запроса
switch($query) {
case 'getKinds': // Запрос на получение видов транспорта
// Сохраним в переменную значение выбранного типа транспорта
$type_id = trim($_POST['type_id']); // Очистим его от лишних пробелов
// Формируем массив с ответом
$result = NULL;
$i = 0;
foreach ($types[$type_id] as $kind_id => $kind) {
$result[$i]['kind_id'] = $kind_id;
$result[$i]['kind'] = $kind;
$i++;
}
break;
case 'getCategories': // Запрос на получение видов транспорта
// Сохраним в переменные значения выбранных типа транспорта и вида транспорта
$type_id = trim($_POST['type_id']); // Очистим их от лишних пробелов
$kind_id = trim($_POST['kind_id']);
// Формируем массив с ответом
$result = NULL;
$i = 0;
foreach ($kinds[$type_id][$kind_id] as $category_id => $category) {
$result[$i]['category_id'] = $category_id;
$result[$i]['category'] = $category;
$i++;
}
break;
default:
// Если данные не определены
$result = NULL;
break;
}
}
// Преобразуем данные в формат json, чтобы их смог обработать JavaScript-сценарий, приславший запрос
echo json_encode($result);
?>
我想导航页面显示列表中的所有元素,并且当您选择某些内容时仅显示相关元素。请帮忙解决这个问题。
答案 0 :(得分:0)
如果你没有使用Javascript - 因为你还没有发布JS代码..
您需要将HTML中的详细信息发送到PHP页面。
例如,您的select标签没有'name'来标识它到PHP POST页面..
所以你需要这样的东西:
<select id="type" name="type_id" multiple> ....
该名称然后通知php您将值发送到$ _POST ['type_id'];
修复HTML以符合PHP的期望应解决您的问题..
编辑:(更多信息) HTML需要将您想要的信息和值发送到PHP代码,以便PHP可以使用它。如果您使用.ajax将数据发送到PHP但您的HTML未命名..
你的php $ _POST ['NAME_OF_INPUT'];
来自HTML'name'标签..例如:
<?php
if(isset($_POST['testName']))
echo "You entered : ".$_POST['testName'];
&GT;
<form action="" method="POST">
<input name="testName" type="text"/>
<button>Submit</button>
//你的代码在这里