Location: PHPKode > scripts > OO PHP Library > oo-php-library-1-8a/examples/TTable_example.php
<?
/*
 $Id: TTable_example.php,v 1.2 2001/08/09 13:14:58 nightmar Exp $
*/

// include all misc files

include "localconf.php";
error_reporting(255);

/*
   very simple table
   3rows x 4columns, each cell contains only textual and numeric data

   we'll use TRow's ability to create empty TCell objects if necessary

*/

// create 4 cells
$template_row = new TRow(0,0,4);


$table1 = new TTable(0, 0, $template_row, array("border"=>"1", "width"=>500));

// now inserting 3 rows with data
$table1->set_data(array(array("Project1", "Bugs", "3 open", "3 total"),
						array("Hardworkers", "Bugs", "0 open", "8 total")));
$table1->insert(array("Lazy Onez", "Bugs", "36 open", "36 total"));
$table1->output();


/*
   another example: how to generate tables with forms
*/

/* let's define 2D array to use it later in all examples
   last field is a project id
*/


$sample_data = array(array("Project1", "Bugs", "3", "3 ", "1"),
  					 array("Hardworkers", "Bugs", "0 ", "8", "2"),
					 array("Lazy Onez", "Bugs", "36", "36", "3"),
					 array("Lazy Onez", "Patches", "28", "28", "3"));


$template_row = new TFormRow($PHP_SELF /* , "GET" is a default action type*/);
$template_row->insert(new TCellInput("ProjectName"));
$template_row->insert("");
$template_row->insert(new TCellInput("open", "",  5));
$template_row->insert(new TCellInput("total", "",  5));
$template_row->insert(new THiddenField("id", "notset"));
$template_row->insert(new TCellSubmitButton("Submit"));

/* let's create header object in-place */
$table = new TTable (new TRow(array("bgcolor"=>"#CCCCCC"),
	  					      array("Project Name", "Task type", "Open", "Total", ""))
    			     , 0 /* skip footer */, $template_row, 0);


$table->set_data($sample_data);
$table->output();


/* my_rows class prints light and dark rows */
class my_rows extends TFormRow {
 	function start() {
 		static $state=0;
 		if ($state) {
 			$this->bgcolor = "#CCCCCC";
 		}
 		else {
 			$this->bgcolor = "#AAAAAA";
 		}
 		$state = 1 - $state;
 		TFormRow::start();
 	}
}




$template_row = new my_rows($PHP_SELF, "GET");
$template_row->insert(new TCellInput("name"));
$template_row->insert(new TCellInput("type", "",  5));
$template_row->insert("");
$template_row->insert("");
$template_row->insert("");
$template_row->insert(new THiddenField("id", "notset"));
$template_row->insert(new TCellSubmitButton("Submit"));

$header_row = new TRow(array("bgcolor"=>"#999999"),
	  				   array("Project Name", "Task type", "Open", "Total"), 6);


$table = new TTable($header_row, 0, $template_row, 0);
$table->set_data($sample_data);

// if case the object is inserted in the table,
// the output() method of that object will be called
$table->insert(new TText("<td colspan=6>Skipping...</td>"));
$table->insert(array("Other projects", "--", 5, 6, ""));

// another way to set table properties
$table->border=1;
$table->spacing=0;
$table->padding=5;
$table->output();

?>
Return current item: OO PHP Library