1:
<?php session_start(); ?>
2:
3:
<?php
4:
5:
function dropdownfunction($webpage, $tableName) {
6:
7:
// Här definieras kategorier och underkategorier. Kategorier (första ordet) och underkategorier (resterande ord). "Alla" läggs in automatiskt.
8:
$kategorilista[0] = "pop,brittpop,dansbandspop,övrigt";
9:
$kategorilista[1] = "imitationer,amerikanska,kandis";
10:
$kategorilista[2] = "rock,hårdrock,metal";
11:
$kategorilista[3] = "disco,70-tal,80-tal";
12:
13:
//Dropdown menyerna
14:
15:
// Dropdown sortera
16:
$re_html = '<form action="gohere.php" method="get">';
17:
$re_html .= '<input type="hidden" name="select" value="'.$_GET['select'].'">';
18:
$re_html .= ' SORTERA ';
19:
$re_html .= '<select name="sortmc" id="sortering" onchange="ajax(1, \''.$_GET['select'].'\')">';
20:
$re_html .= '<option'; if ($_GET['sortmc']=='ingen') $re_html .= ' selected="selected"'; $re_html .=' value="ingen">Ingen</option>';
21:
$re_html .= '<option'; if ($_GET['sortmc']=='downloads') $re_html .= ' selected="selected"'; $re_html .=' value="downloads">Downloads</option>';
22:
$re_html .= '<option'; if ($_GET['sortmc']=='datum') $re_html .= ' selected="selected"'; $re_html .=' value="datum">Datum</option>';
23:
$re_html .= '<option'; if ($_GET['sortmc']=='title') $re_html .= ' selected="selected"'; $re_html .=' value="title">Title</option>';
24:
$re_html .= '</select>';
25:
26:
// Kontrollerar vilken kategori som är vald och skickar tillbaks underkategorierna i en array
27:
function check_category($cat_item, $cat_array) {
28:
$categorywords = array();
29:
$count = 0;
30:
$items = count($cat_array);
31:
// Placerar alla huvudkategorier i en array
32:
for ($i = 0; $i < $items; $i++) {
33:
$ex = explode(",", $cat_array[$i]);
34:
$categorywords[$i] = $ex[0];
35:
}
36:
37:
// Tar fram index för rätt kategori
38:
$i = 0;
39:
while ($categorywords[$i] != $cat_item)
40:
$i++;
41:
// Ta fram en array på underkategorierna
42:
$subcategories = explode(",", $cat_array[$i]);
43:
$notused = array_shift($subcategories);
44:
return $subcategories;
45:
}
46:
47:
48:
// Dropdown lists
49:
$choice = "alla";
50:
$re_html .= ' KATEGORI ';
51:
$re_html .= '<select name="categorymc" id="kategori" onChange="ajax(1, \''.$_GET['select'].'\')">';
52:
$re_html .= '<option'; if ($_GET['categorymc']=='alla') { $re_html .= ' selected="selected"'; $choice = "alla"; } $re_html .=' value="alla">Alla</option>';
53:
54:
//Lägg till valmöjlighter i category
55:
$items = count($kategorilista);
56:
for ($cat = 0; $cat < $items; $cat++) {
57:
$pieces = explode(",", $kategorilista[$cat]);
58:
$re_html .= '<option'; if ($_GET['categorymc']=="$pieces[0]") { $re_html .= ' selected="selected"'; $choice = $pieces[0]; } $re_html .=' value="'.$pieces[0].'">'.$pieces[0].'</option>';
59:
}
60:
$re_html .= '</select>';
61:
62:
if ($choice != "alla")
63:
{
64:
$re_html .= ' ';
65:
//Lägg till valmöjlighter i subcategory, baserat på category
66:
$re_html .= '<select name="subcategorymc" id="underkategori" onChange="ajax(1, \''.$_GET['select'].'\')">';
67:
$re_html .= '<option'; if ($_GET['subcategorymc']=='alla') $re_html .= ' selected="selected"'; $re_html .=' value="alla">Alla</option>';
68:
69:
$subs = check_category($choice, $kategorilista);
70:
$items = count($subs);
71:
for ($subcounter = 0; $subcounter < $items; $subcounter++) {
72:
$subshort = $subs[$subcounter];
73:
$re_html .= '<option'; if ($_GET['subcategorymc']=="$subshort") $re_html .= ' selected="selected"'; $re_html .=' value="'.$subshort.'">'.$subshort.'</option>';
74:
}
75:
$re_html .= '</select>';
76:
}
77:
78:
$re_html .= '</form>';
79:
echo $re_html;
80:
}
81:
?>