Hi,
I have this page which sorts the date, price and type .
Trouble is I only want listings called from the db table which have the same input for one of the fields. I need to be able to call listings from the one suburb even though all suburbs go into the same db table. BTW the suburb field is only viewable in the db row.
Is it possible? If it is possible, wouldn't that code go in the config.php?
Any help appreciated.
the list.php code:
<?php
include("config.php");
if(isset($_GET['orderby'])){ $orderby = strtolower($_GET['orderby']); }else{ $orderby = "date"; }
if(isset($_GET['how'])){ $how = strtoupper($_GET['how']); }else{ $how = "DESC"; }
$acceptable_orberby_values = array("date", "property_type", "property_price");
$acceptable_how_values = array("ASC", "DESC");
if(!in_array($orderby, $acceptable_orberby_values)){ $orderby = "date"; }
if(!in_array($how, $acceptable_how_values)){ $how = "DESC"; }
mysql_connect($DB_server, $DB_user, $DB_pass) or die("<p>Could not connect to database.</p>");
mysql_select_db($DB_name) or die("<p>Could not select database.</p>");
$sql = "SELECT * FROM $DB_table ORDER BY `$orderby` $how";
if($result = mysql_query($sql)){
if(mysql_num_rows($result) > 0){
?>
<table border='1' cellpadding='1' cellspacing='1' width='100%'>
<tr align='center'>
<td>list_date (<a href="lyonsort.php?orderby=date&how=ASC">ASC</a>) (<a href="lyonsort.php?orderby=date&how=DESC">DESC</a>)</td>
<td>address</td>
<td>price (<a href="lyonsort.php?orderby=property_price&how=ASC">ASC</a>) (<a href="lyonsort.php?orderby=property_price&how=DESC">DESC</a>)</td>
<td>type (<a href="lyonsort.php?orderby=property_type&how=ASC">ASC</a>) (<a href="lyonsort.php?orderby=property_type&how=DESC">DESC</a>)</td>
<td>block</td>
<td>beds</td>
<td>bath</td>
<td>EER</td>
</tr>
<?php
while($n = mysql_fetch_array($result)){
$date = $n['date'];
$address = $n['address'];
$property_price = "$". $n['property_price'];
$property_type = $n['property_type'];
$block_size = $n['block_size'];
$no_of_bedrooms = $n['no_of_bedrooms'];
$no_of_bathrooms = $n['no_of_bathrooms'];
$energy_efficiency_rating = $n['energy_efficiency_rating'];
echo<<<ENDL
<tr>
<td>$date</td>
<td>$address</td>
<td>$property_price</td>
<td>$property_type</td>
<td>$block_size</td>
<td>$no_of_bedrooms</td>
<td>$no_of_bathrooms</td>
<td>$energy_efficiency_rating</td>
</tr>
ENDL;
}
echo "</table>";
}else{ // This else if in case there were no results -- matches our: if(mysql_num_rows($result) > 0){
echo "<p>There are no results to return.</p>";
}
}else{ // This else is incase our query was invalid -- matches our: if($result = mysql_query($sql)){
echo "<p>MySQL query is invalid.</p>";
}
?>