Is there a way to sort the output on this HTML_Table?
Posted: Wed Mar 09, 2011 5:00 pm
I'm trying to figure out how to sort the output the data on this HTML_Table. Can someone please help me? Thanks in advance.
Code: Select all
<?php
if ($_POST){
$county = $_POST['county'];
$rooms = $_POST['type'];
$rent = $_POST['rent'];
$rent_min = $rent - 500;
}
$dbase = mysql_connect ( ' ', ' ', ' ' );
mysql_select_db ( ' ', $dbase );
if($county){
$sql = "SELECT * FROM `apartments` WHERE `county` = '".$county."' AND `rooms` = '".$rooms."' AND `rent` < '".$rent."' AND `rent` > '".$rent_min."' ";
}else{
$sql = "SELECT * FROM `apartments`";
}
//include the class
require_once("/home/genesis/php/HTML/Table.php");
//set table attributes
$attributes = array("width"=>"600","border"=>"1", "align"=>"center");
//create the table class
$table = new HTML_Table($attributes);
//build our first row
$contents = array("County", "Town", "Phone Number", "Rooms", "Baths", "Rent");
$attributes = array("bgcolor"=>"#336699");
$table->addRow($contents, $attributes, "TH");
//loop through and add our data
$attributes = array("bgcolor"=>"#COCOCO");
$res = mysql_query($sql, $dbase);
while($row = mysql_fetch_assoc($res)) {
$contents = array($row['county'], $row['town'], $row['phone'], $row['rooms'], $row['bath'], $row['rent'],);
$table->addRow($contents, $attributes);
}
$table->altRowAttributes(1, null, array("class"=>"alt"));
$table->display();
?>