I have a search box which a user can search their favorite cases. I have ordered the search results by date, but I want to make it optional for a user and they can choose it by themselves:
$orders = array("date","price"); //field names
$key = array_search($_GET['sort'],$orders)); // see if we have such a name
$orderby = $orders[$key]; //if not, first one will be set automatically. smart enuf :)
$quer = "SELECT*FROM ".$db_table." WHERE
`case`=
'apartment'
AND `field`=
'sell'
ORDER BY
$orderby";
$query=mysqli_query($connect,$quer)
or die(mysqli_error());
?>
<?php while($row = mysqli_fetch_array($query)):
echo "price ";
echo "address ";
//to simplify the code I do not write the rest
?>
<?php endwhile;?>
For example, order by date or price or other things. How can I do it?
Users can get values from dropdownlist:
<select>
<option value="date">order by date</option>
<option value="price">order by price</option>
</select>