Badtable


Getting Started

This section will outline common usage of BadTable.

A Simple Example

Here is an example showing how you can create a table from a multi-dimensional array. Note that the first array index will become the table heading (or you can set your own headings using the set_heading() function described in the function reference).

$this->load->library('badtable');

$data = array( 
    array('Name', 'Color', 'Size'), 
    array('Fred', 'Blue', 'Small'), 
    array('Mary', 'Red', 'Large'), 
    array('John', 'Green', 'Medium')     
); 
 
echo $this->badtable->generate($data);

From a db query

Here is an example of a table created from a database query result. The table class will automatically generate the headings based on the table names (or you can set your own headings using the set_heading() function described in the function reference).

$this->load->library('badtable');

$query = $this->db->query("SELECT * FROM groups"); 
		 
echo $this->badtable->generate($query);

Using row arrays

Here is an example showing how you might create a table adding by adding row arrays and how to specify attributes for individual rows:

$this->load->library('badtable');

// set heading
$this->badtable->set_heading(array('Name', 'Color', 'Size'));

// add class to this row
$this->badtable->add_row(array('John', 'Green', 'Medium'), array('class' => 'highlight'));
$this->badtable->add_row(array('Fred', 'Blue', 'Small'));
$this->badtable->add_row(array('Mary', 'Red', 'Large'));
		 
echo $this->badtable->generate();

Using discrete parameters

Here is an example showing how you might create a table adding by adding rows using discrete parameters and how to specify attributes for individual rows:

$this->load->library('badtable');

// set heading
$this->badtable->set_heading('Name', 'Color', 'Size');

// add class to this row
$this->badtable->add_row('John', 'Green', 'Medium', array('class' => 'highlight'));
$this->badtable->add_row('Fred', 'Blue', 'Small');
$this->badtable->add_row('Mary', 'Red', 'Large');
		 
echo $this->badtable->generate();