Hi,
Had a little crack at your code, and started reqorking it. but at a certain pont I am not sure what you try to achieve. Please look at the code, and tell me what the idea is from the commented point onwards.
<?php
// set defaults
$default_order = 1;
$default_how = 1;
if(isset($_GET['orderby']) && isset($_GET['how']))
{
$orderby_nr = $_GET['orderby'];
$how_nr = $_GET['how'];
}
// safer:
$order_array = array(
1=>"date",
2=>"type",
3=>"price");
$how_array = array(
1=>"ASC",
2=>"DESC");
// get the sort colum
if(array_key_exists($orderby_nr, $order_array))
{
$orderby = $order_array[$orderby_nr];
}
else
{
$orderby = $order_array[$default_order];
}
// get the sortorder
if(array_key_exists($how_nr, $how_array))
{
$how = $how_array[$how_nr];
}
else
{
$how = $order_array[$default_how];
}
// query is ready
$query = "SELECT * FROM listings ORDER BY $orderby $how"; // OK
// create the table header
$table = "<table border='1' cellpadding='1' cellspacing='1' width='100%'>
<tr>";
foreach($order_array as $key=>$value)
{
$table .= "
<td align='center' width='10%' bgcolor='#FFFFCC'>
<a href=\"example.php?orderby=".$key."&how=2\">".$value."</a>
</td>";
}
$table .= "</tr>";
// -----------------------
// From here I am not sure what you want to do!??
// connect
$connection = mysql_connect("mysql.myhost", "myusername", "mypassword") or die("Error connecting to database");
mysql_select_db("my_db", $connection);
$result = mysql_query($query) or die('Shoop! What did I do!!!');
if($result)
{
while($row = mysql_fetch_array($result))
{
echo "<tr><td>".$row['date']."</tr></td>"
}
}
// You start a new query here?
$result = mysql_query("SELECT COUNT(*) AS `Rows` , `date` FROM `listings` GROUP BY `date` ORDER BY `date` DESC", $connection) or die("error querying database");
?>
<table border='1' cellpadding='1' cellspacing='1' width='100%'>
<tr align='center'>
<td align='center' width='10%' bgcolor='#FFFFFF'>22/05/06</td>
<td align='center' width='40%' bgcolor='#FFFFFF'><a href="1/ex_1.htm">59 Burnie Street</a></td>
<td align='center' width='15%' bgcolor='#FFFFFF'> $430,000 </td>
<td>
<td align='center' width='10%' bgcolor='#FFFFFF'> HOUSE</td></td>
<td align='center' width='10%' bgcolor='#FFFFFF'>678m2</td>
<td align='center' width='5%' bgcolor='#FFFFFF'>2</td>
<td align='center' width='5%' bgcolor='#FFFFFF'>1</td>
<td align='center' width='5%' bgcolor='#FFFFFF'>1.5</td>
</tr>
</table>
<table border='1' cellpadding='1' cellspacing='1' width='100%'>
<tr align='center'>
<td align='center' width='10%' bgcolor='#FFFFFF'>31/06/06</td>
<td align='center' width='40%' bgcolor='#FFFFFF'>test3 address</td>
<td align='center' width='15%' bgcolor='#FFFFFF'>$200,000 </td>
<td align='center' width='10%' bgcolor='#FFFFFF'>UNIT</td>
<td align='center' width='10%' bgcolor='#FFFFFF'> </td>
<td align='center' width='5%' bgcolor='#FFFFFF'> </td>
<td align='center' width='5%' bgcolor='#FFFFFF'> </td>
<td align='center' width='5%' bgcolor='#FFFFFF'> </td>
</tr>
</table>