PHP Classes

PHP Array into HTML Table: Generate HTML tables from data in arrays

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 234 All time: 8,111 This week: 50Up
Version License PHP version Categories
array-to-html-table 1.0.0GNU General Publi...5.4HTML, PHP 5
Description 

Author

This class can generate HTML tables from data in arrays

It can take arrays with data for the headers and body and generates HTML for a table.

The class also allows to pass array of CSS classes to assign to each table column, classes for each row, and hide specific columns.

Picture of Alexandre Sinício
  Performance   Level  
Name: Alexandre Sinício <contact>
Classes: 7 packages by
Country: Brazil Brazil
Age: 40
All time rank: 2095136 in Brazil Brazil
Week rank: 131 Up11 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 3x

Example

<?php
   
use alesinicio\HTMLTable;

    require
"../HTMLTable.php";
   
   
$arrHeaders = array(
       
"First column", "Second column", "Third column", "Fourth column"
   
);
   
   
$arrData = array(
        array(
"this", "is", "first", "row"),
        array(
"could", "come", "from", "database")
    );
   
   
$arrTDClasses = array("red", "blue", "green", "grey");
   
   
$table = new HTMLTable();
   
$table->setData($arrData);
   
$table->setHeaders($arrHeaders);
   
$table->setTdClasses($arrTDClasses);
    echo
$table->getHTML();
   
    echo
"<style>
        .red{background-color: red;}
        .green{background-color: green;}
        .blue{background-color: blue;}
        .grey{background-color: grey;}
        </style>"
;


Details

It can be a pain to format HTML tables. It can be a pain to output that array of data in an user-friendly way. This class tries to simplify the job of creating these tables. The basic usage allows to output HTML code with just three lines. The class also provides enough flexibility to set custom ID and classes to the table, rows and even individual cells. Every suggestion and/or bug report will be mostly appreciated.

  Files folder image Files (7)  
File Role Description
Accessible without login Plain text file 01_basic_usage.php Example Example - Basic usage
Accessible without login Plain text file 02_defining_classes.php Example Example - Defining classes to elements
Accessible without login Plain text file 03_custom_function_classes.php Example Example - Defining classes to elements through custom functions
Accessible without login Plain text file 04_custom_function_tr_id.php Example Example - Defining ID for 'tr' tags
Accessible without login Plain text file 05_hiding_columns.php Example Example - Hiding unwanted columns
Plain text file HTMLTable.php Class Source class file
Accessible without login Plain text file README.md Data README

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:234
This week:0
All time:8,111
This week:50Up