PHP Classes

File: data_table_test.php

Recommend this page to a friend!
  Classes of Moellers Oma   data_table   data_table_test.php   Download  
File: data_table_test.php
Role: Unit test script
Content type: text/plain
Description: Example and test file
Class: data_table
Generates HTML tables from a data array
Author: By
Last change:
Date: 21 years ago
Size: 4,871 bytes
 

Contents

Class file image Download
<?php
//data array
$data[0]["col1"] = "1 This is the value for the first column and first row";
$data[0]["col2"] = "1 value for the second column first row";
$data[0]["col3"] = "1 1";
$data[0]["col4"] = "hidden column";
$data[1]["col1"] = "2 This is the value for the first column and second row";
$data[1]["col2"] = "2 value for the second column second row";
$data[1]["col3"] = "2 1";
$data[1]["col4"] = "hidden column";
$data[2]["col1"] = "3 This is the value for the first column and third row";
$data[2]["col2"] = "3 value for the second column third row";
$data[2]["col3"] = "3 1";
$data[2]["col4"] = "hidden column";
$data[3]["col1"] = "4 This is the value for the first column and 4th row";
$data[3]["col2"] = "4 value for the second column 4th row";
$data[3]["col3"] = "4 1";
$data[3]["col4"] = "hidden column";
$data[4]["col1"] = "5 This is the value for the first column and 5th row";
$data[4]["col2"] = "5 value for the second column 5th row";
$data[4]["col3"] = "5 1";
$data[4]["col4"] = "hidden column";
$data[5]["col1"] = "6 This is the value for the first column and 6th row";
$data[5]["col2"] = "6 value for the second column 6th row";
$data[5]["col3"] = "6 1";
$data[5]["col4"] = "hidden column";
$data[6]["col1"] = "7 This is the value for the first column and 7th row";
$data[6]["col2"] = "7 value for the second column 7th row";
$data[6]["col3"] = "7 1";
$data[6]["col4"] = "hidden column";
$data[7]["col1"] = "8 This is the value for the first column and 8th row";
$data[7]["col2"] = "8 value for the second column 8th row";
$data[7]["col3"] = "8 1";
$data[7]["col4"] = "hidden column";
$data[8]["col1"] = "9 This is the value for the first column and 9th row";
$data[8]["col2"] = "9 value for the second column 9th row";
$data[8]["col3"] = "9 1";
$data[8]["col4"] = "hidden column";
$data[9]["col1"] = "10 This is the value for the first column and 10th row";
$data[9]["col2"] = "10 value for the second column 10th row";
$data[9]["col3"] = "10 1";
$data[9]["col4"] = "hidden column";
//Empty data, not shown in example
$data[10]["col1"] = "";
$data[10]["col2"] = "";
$data[10]["col3"] = "";
$data[10]["col4"] = "";

//Table config
$tbl_conf["align"] = "center";
$tbl_conf["width"] = "100%";
$tbl_conf["cellspacing"] = 0;
$tbl_conf["cellpadding"] = 2;
$tbl_conf["border"] = 1;

//th header config
$th_conf[0]["width"] = "50%";
$th_conf[1]["width"] = "30%";
$th_conf[2]["width"] = "20%";

//td data config
$td_conf[0]["align"] = "left";
$td_conf[1]["align"] = "center";
$td_conf[2]["align"] = "right";

//headers
$headers[0]["order"] = "col1";
$headers[1]["order"] = "col2";
$headers[2]["order"] = "col3";
$headers[3]["order"] = "col4";
$headers[0]["show"] = "Column 1";
$headers[1]["show"] = "Column 2";
$headers[2]["show"] = "Column 3";
$headers[3]["show"] = "Hidden Column";

//Column config
$col_conf[0] = "link";
$col_conf[2] = "email";

//tr bgcolors
$colors[0] = "#999999";
$colors[1] = "#CCCCCC";

//Header pre- and suffix
$header_prefix = '<h3>';
$header_suffix = '</h3>';

//Data pre- and suffix
$data_prefix = '<i>';
$data_suffix = '</i>';

//Hide column 3
$hidden_column = 3;

//Make it sortable
$sortable = true;

//Sort it y and how
$sort_by = "col1";
$sort_mode = "ASC";

//Max datasets shown each site
$max_data = 3;

//Text for next and previous link
$next_text = "Next&nbsp;&gt;&gt;";
$prev_text = "&lt;&lt;&nbsp;Previous";

//Show empty datasets
$show_empty = false;

//show amount of pages
$show_page_count = true;

//assigning values and generating table
require_once("data_table.class.php");
$data_table = new data_table();
$data_table->set_tbl_config($tbl_conf);
$data_table->set_td_config($td_conf);
$data_table->set_th_config($th_conf);
$data_table->set_colors($colors);
$data_table->set_data($data);
$data_table->set_header($headers);
$data_table->set_header_prefix($header_prefix);
$data_table->set_header_suffix($header_suffix);
$data_table->set_data_prefix($data_prefix);
$data_table->set_data_suffix($data_suffix);
$data_table->set_col_config($col_conf);
$data_table->set_hidden_column($hidden_column);
$data_table->is_sortable($sortable);
$data_table->sort_data($sort_by, $sort_mode);
$data_table->set_max_data($max_data);
$data_table->set_next_text($next_text);
$data_table->set_previous_text($prev_text);
$data_table->show_empty_data($show_empty);
$data_table->show_page_count($show_page_count);

$html = $data_table->get_html();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>Testpage for datatable of Sven Zurnieden</title>
</head>

<body>
<h1>Testpage for datatable of Sven Zurnieden</h1>
<br>
<br>
<?php echo $html?>
<br>
<br>
Written by <a href="mailto:sven.zurnieden@t-online.de">Sven Zurnieden</a>
</body>
</html>