Ahoj,
mám databázi filmů a seriálů a snažím se pomocí selectu vyfiltrovat to co přesně hledám. Zatím to mám takto:
<select name="druh" onchange="this.form.submit()">
<option value=""> zobrazit
<?php
if($druh=="serial")
$selected_serial = "selected";
else
$selected_serial = "";
if($druh=="film")
$selected_film = "selected";
else
$selected_film = "";
?>
<option value="serial" <?php echo $selected_serial?>> seriály
<option value="film" <?php echo $selected_film?>> filmy
</select>
<select name="hodnoceni" onchange="this.form.submit()">
<option value=""> hodnocení
<?php
if($hodnoceni=="top")
$selected_top = "selected";
else
$selected_top = "";
if($hodnoceni=="worst")
$selected_worst = "selected";
else
$selected_worst = "";
?>
<option value="top" <?php echo $selected_top?>> od nejlepšího
<option value="worst" <?php echo $selected_worst?>> od nejhoršího
</select>
<select name="zanr" onchange="this.form.submit()">
<option value=""> žánr
<?php
sort($zanr_filtr);
for($i=1;$i<count($zanr_filtr);$i++){
if($zanr==$zanr_filtr[$i])
$selected = "selected";
else
$selected = "";
echo "<option value=\"$zanr_filtr[$i]\" $selected> $zanr_filtr[$i]";
}
?>
</select>
<select name="videno" onchange="this.form.submit()">
<option value=""> historie
<?php
if($videno=="yes")
$videno_y = "selected";
else
$videno_y = "";
if($videno=="no")
$videno_n = "selected";
else
$videno_n = "";
?>
<option value="yes" <?php echo $videno_y;?>> viděno
<option value="no" <?php echo $videno_n;?>> neviděno
</select>
<select name="jazyk" onchange="this.form.submit()">
<option value=""> zvuková stopa
<?php
sort($jazyk_filtr);
for($i=1;$i<count($jazyk_filtr);$i++){
if($jazyk==$jazyk_filtr[$i])
$selected = "selected";
else
$selected = "";
echo "<option value=\"$jazyk_filtr[$i]\" $selected> $jazyk_filtr[$i]";
}
?>
</select>
elseif($druh=="" and $zanr=="" and $videno!="" and $jazyk!=""){
$Podminka .= "WHERE audio LIKE '%".$jazyk."%' ";
if($videno=="yes") {
for($i = 0; $i <= $csfd_id_historie_count - 1; $i++){
if($i == $csfd_id_historie_count - 1)
$nic .= "'".$csfd_id_historie[$i]."'";
else
$nic .= "'".$csfd_id_historie[$i]."',";
}
$Podminka .= "AND csfd_id in ($nic) ";
}
elseif ($videno=="no") {
for($i = 0; $i <= $csfd_id_historie_count - 1; $i++){
if($i == $csfd_id_historie_count - 1)
$nic .= "'".$csfd_id_historie[$i]."'";
else
$nic .= "'".$csfd_id_historie[$i]."',";
}
$Podminka .= "AND csfd_id not in ($nic)";
}
}
elseif($druh=="" and $zanr!="" and $videno!="" and $jazyk!=""){
$Podminka .= "WHERE genres LIKE '%".$zanr."%' AND audio LIKE '%".$jazyk."%' ";
if($videno=="yes") {
for($i = 0; $i <= $csfd_id_historie_count - 1; $i++){
if($i == $csfd_id_historie_count - 1)
$nic .= "'".$csfd_id_historie[$i]."'";
else
$nic .= "'".$csfd_id_historie[$i]."',";
}
$Podminka .= "AND csfd_id in ($nic) ";
}
elseif ($videno=="no") {
for($i = 0; $i <= $csfd_id_historie_count - 1; $i++){
if($i == $csfd_id_historie_count - 1)
$nic .= "'".$csfd_id_historie[$i]."'";
else
$nic .= "'".$csfd_id_historie[$i]."',";
}
$Podminka .= "AND csfd_id not in ($nic)";
}
}
A tak dále ve stejném duchu.
Jak se to dá udělat jinak, abych nemusel používat elseif?