Jump to content

Help with using HTML_Table


frank_solo

Recommended Posts

I'm new to this forum and I would like to thank everyone in advance for the help. I've got a drop down menu where someone can make the selection and I need it to display in a table using HTML_Table, but all I get is the headers. I'm providing the code down below can someone please help me? Thanks.

 <?php
if ($_POST){
$county = $_POST['county'];
$rooms = $_POST['type'];
$rent = $_POST['rent'];
$rent_min = $rent - 500;
}

$dbase = mysql_connect ( 'localhost', ' ', ' ' );
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`";
}			

$res = mysql_query($sql, $dbase);
require_once 'HTML/Table.php';

$attrs = array('width' => '600');
$table = new HTML_Table();
$table->setAttributes($attrs);

for ($nr = 0; $nr < count($data); $nr++) {
  	$table->setHeaderContents($nr+1, 0, (string)$nr);
  	for ($i = 0; $i < 4; $i++) {
    if ('' != $data[$nr][$i]) {
      $table->setCellContents($nr+1, $i+1, $data[$nr][$i]);
    }
  }
}
$altRow = array('bgcolor' => '#999969');
$table->altRowAttributes(1, null, $altRow);
   // Create the table object

   $table = new HTML_Table();

   // Set the headers

   $table->setHeaderContents(0, 0, "County");
   $table->setHeaderContents(0, 1, "Town");
   $table->setHeaderContents(0, 2, "Phone");
   $table->setHeaderContents(0, 3, "Rooms");
   $table->setHeaderContents(0, 4, "Bath");
   $table->setHeaderContents(0, 5, "Rent");
   $hrAttrs = array('bgcolor' => '#333333');
   $table->setRowAttributes(0, $hrAttrs, true);
   $table->setColAttributes(0, $hrAttrs);

   $rownum = 1; // don't overwrite header of table
	while($row = mysql_fetch_assoc($res))


   $table->altRowAttributes(1, null, array("class"=>"alt"));

   // Output the data

   echo $table->toHtml();

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.