hello im using this code to do search
<form action="arama.php" method="get">
<input type="text" name="lol">
<select name='kategori'>
<option value="tum">Tum kategoriler</option>
<?
while ($kat = mysql_fetch_array($kategori_isim)) {
echo "
<option value=".$kat[kategori_isim].">".$kat[kategori_isim]."</option>";
}
?>
</select>
<input type="submit" value="ara">
</form>
<?
$lol = mysql_real_escape_string($_GET['lol']);
$kategori = mysql_real_escape_string($_GET['kategori']);
if ($kategori == "tum") {
$ara = mysql_query("select * from dosyalar where baslik like '%$lol%'");
}
else {
$ara = mysql_query("select * from dosyalar where baslik like '%$lol%' order by kategori = '%$kategori%'");
}
?>
search by term works but not listing by kategori.. what can i do?
I’m not sure I understand the question (I can’t really figure out what those fields mean), but I think that your second query should be more like:
ORDER BYonly specifies how to sort the results, you can only use a column name, not a check as in your code.Extending my answer: the
ORDER BY kategori = '%$kategori%'isn’t a syntax error but I don’t think it does anything useful. The checkkategori = '%$kategori%'will always be false (unless you have a value with percent signs both at start and at end) so theORDER BYclause will be useless and you will just do the same select you’re doing in the other branch of theifblock.Specifying
ORDER BY kategori = '$kategori'will return 0 for all the records wherekategoriis not equal to$kategori, 1 for the ones where it matches. This will basically sort all the matching rows at the end of your query.