I have a filter on MySQL query. I can filter entries as I want. But after filtering, I cannot set values as selected on option value. My code;
<form method="POST">
<label>İller:</label><select style="width:150px" name="iller">
<OPTION VALUE=''>Hepsi</OPTION>
<option value="İstanbul">İstanbul</option>
<option value="Ankara">Ankara</option>
<option value="Bolu">Bolu</option>
</select>
<label>Bölümler:</label><select style="width:150px" name="bolum">
<OPTION VALUE=''>Hepsi</OPTION>
<option value="Makine Mühendisliği">Makine Mühendisliği</option>
<option value="Endüstri Mühendisliği">Endüstri Mühendisliği</option>
<option value="Elektrik Mühendisliği">Elektrik Mühendisliği</option>
</select>
<input class="button" type="submit" name="submit" value="Filtrele" /></td>
</form>
<?php
$db_connection = mysqli_connect($host,$user,$password,$dbname);
$query="SELECT * FROM osym";
$sql=$query;
$iller = $_POST['iller'];
$bolum = $_POST['bolum'];
mysqli_real_escape_string($db_connection,$_POST['iller']);
mysqli_real_escape_string($db_connection,$_POST['bolum']);
$conditions = array();
if($iller !="") {
$conditions[] = " Il='$iller'";
}
if($bolum !="") {
$conditions[] = " Bolum='$bolum'";
}
if (count($conditions) > 0) {
$sql .= " WHERE " . implode(' AND ', $conditions);
}
echo "<table border='1'>
<tr>
<th>Kod</th>
<th>İl</th>
<th>Okul</th>
<th>Bölüm</th>
<th>Dili</th>
<th>Öğretim</th>
<th>Burs</th>
<th>Kontenjan</th>
<th>Puan Türü</th>
<th>Sıra</th>
<th>Taban P.</th>
<th>Tavan P.</th>
</tr>";
mysqli_query($db_connection,"SET NAMES UTF8");
if (isset($_POST['submit'])) {
$result = mysqli_query($db_connection,$sql);
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['Kod'] . "</td>";
echo "<td>" . $row['Il'] . "</td>";
echo "<td>" . $row['Okul'] . "</td>";
echo "<td>" . $row['Bolum'] . "</td>";
echo "<td>" . $row['Dili'] . "</td>";
echo "<td>" . $row['Ogr'] . "</td>";
echo "<td>" . $row['Burslu'] . "</td>";
echo "<td>" . $row['Kontenjan'] . "</td>";
echo "<td>" . $row['PuanT'] . "</td>";
echo "<td>" . $row['Sira'] . "</td>";
echo "<td>" . $row['TabPuan'] . "</td>";
echo "<td>" . $row['TavPuan'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
?>
Whenever I select an option and hit 'Filtrele' button, all option names return to "Hepsi".
I have tried putting
<?php if ($iller="İstanbul") {echo "selected"; } ?>
in
<option value="İstanbul">
tag but it didn't work.
Because of method, i cannot use GET attribute either. I am looking for your help, thanks in advance.