Need help in making the headers clickable and sortable

  • frank_solo
  • Born
  • Born
  • frank_solo
  • Posts: 1

Post 3+ Months Ago

Hello everyone this is my first time I wrote a code using HTML_Table but I would like the headers to be clickable so the user can sort it. Does anyone know how this can be done? Here is the code:
Code: [ Select ]
<?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();
?>
  1. <?php
  2. if ($_POST){
  3.     $county = $_POST['county'];
  4.     $rooms = $_POST['type'];
  5.     $rent = $_POST['rent'];
  6.     $rent_min = $rent - 500;
  7. }
  8.     
  9.     $dbase = mysql_connect ( ' ', ' ', ' ' );
  10.     mysql_select_db ( ' ', $dbase );
  11.             
  12.     if($county){
  13.         $sql = "SELECT * FROM `apartments` WHERE `county` = '".$county."' AND `rooms` = '".$rooms."' AND `rent` < '".$rent."' AND `rent` > '".$rent_min."' ";
  14.     }else{
  15.         $sql = "SELECT * FROM `apartments`";
  16.     }           
  17.     //include the class
  18. require_once("/home/genesis/php/HTML/Table.php");
  19. //set table attributes
  20. $attributes = array("width"=>"600","border"=>"1", "align"=>"center");
  21. //create the table class
  22. $table = new HTML_Table($attributes);
  23. //build our first row
  24. $contents = array("County", "Town", "Phone Number", "Rooms", "Baths", "Rent");
  25. $attributes = array("bgcolor"=>"#336699");
  26. $table->addRow($contents, $attributes, "TH");
  27. //loop through and add our data
  28. $attributes = array("bgcolor"=>"#COCOCO");
  29.     $res = mysql_query($sql, $dbase);
  30.     
  31.         while($row = mysql_fetch_assoc($res)) {
  32.     $contents = array($row['county'], $row['town'], $row['phone'], $row['rooms'], $row['bath'], $row['rent'],);
  33.     $table->addRow($contents, $attributes);
  34. }
  35. $table->altRowAttributes(1, null, array("class"=>"alt"));
  36. $table->display();
  37. ?>


Thank You everyone in advance

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 71 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.