1 |
jonen |
1.1 |
<?php |
2 |
|
|
|
3 |
|
|
/** |
4 |
|
|
* |
5 |
|
|
* The ideal way to use phphtmllib is to use the PageWidget object to create |
6 |
|
|
* complete html documents. If you are managing an existing code base with its |
7 |
|
|
* own structure and templates the ideal setup might not be practical. This |
8 |
|
|
* doesn't mean you can't use phphtmllib. Every descendant from the Container |
9 |
|
|
* object (all the classes for html tags) have a render() method which allow |
10 |
|
|
* you to generate output. |
11 |
|
|
* |
12 |
|
|
* This example generates a short html table fragment that could be inserted |
13 |
|
|
* anywhere in your code. It also attempts to make use of most of the TABLETag |
14 |
|
|
* methods. |
15 |
|
|
* |
16 |
|
|
* $Id: example9.php,v 1.2 2004/03/09 06:15:21 culley Exp $ |
17 |
|
|
* |
18 |
|
|
* @author Culley Harrelson <culley@fastmail.fm> |
19 |
|
|
* @package phpHtmlLib |
20 |
|
|
* @subpackage examples |
21 |
|
|
* @version 1.0.0 |
22 |
|
|
* |
23 |
|
|
*/ |
24 |
|
|
|
25 |
|
|
// load the phphtmllib files |
26 |
|
|
$phphtmllib = $_SERVER["DOCUMENT_ROOT"] . "/phphtmllib"; |
27 |
|
|
include_once("$phphtmllib/includes.inc"); |
28 |
|
|
|
29 |
|
|
|
30 |
|
|
// html_table() is a built-in helper function that returns a table object |
31 |
|
|
$table = html_table('95%', 1, 5, 5); |
32 |
|
|
|
33 |
|
|
// add caption tag as the first element in the table. TR tags should be added with add_row() |
34 |
|
|
$table->add(html_caption("A Caption for the table")); |
35 |
|
|
|
36 |
|
|
// default attributes for TDTags |
37 |
|
|
$table->set_default_col_attributes(array('nowrap' => 'nowrap')); |
38 |
|
|
// default attributes for TRTags |
39 |
|
|
$table->set_default_row_attributes(array('align' => 'center')); |
40 |
|
|
|
41 |
|
|
// these methods are available to all html tags |
42 |
|
|
$table->set_class('myclass'); |
43 |
|
|
$table->set_id('table1'); |
44 |
|
|
$table->set_style('background-color:#EEE'); |
45 |
|
|
$table->set_tag_attribute('name', 'the name of my table'); |
46 |
|
|
|
47 |
|
|
// add some data |
48 |
|
|
for ($i = 0; $i<20; $i++) { |
49 |
|
|
// add_row takes any number of arguments. Each argument will be a cell in the row |
50 |
|
|
// any item can be another html attribute-- the first column here is a BTag object |
51 |
|
|
$table->add_row(html_b(rand(1,1000)), rand(2000,3000), rand(3000,4000)); |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
// update a cells content and attributes-- row and column settings are 0 based |
55 |
|
|
$table->set_cell_content(1, 2, 'this cell is special and it will not wrap because we set no wrap above'); |
56 |
|
|
$table->set_cell_attributes(1, 2, array('align' => 'right', 'style' => 'background-color:#F00;')); |
57 |
|
|
|
58 |
|
|
// udate a row |
59 |
|
|
$table->set_row_attributes(5, array('align' => 'left')); |
60 |
|
|
|
61 |
|
|
// set the summary attribute of the table |
62 |
|
|
$table->set_summary('the sum of all tables'); |
63 |
|
|
|
64 |
|
|
// generate the html |
65 |
|
|
print $table->render(); |
66 |
|
|
|
67 |
|
|
?> |