PHP code example of gbhorwood / tabletown

1. Go to this page and download the library: Download gbhorwood/tabletown library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gbhorwood / tabletown example snippets



Gbhorwood\Tabletown\Table;

// array of column headers
$headers = ['Artist', 'Title', 'Year'];

// array of arrays, one for each row in the table
$rows = [
    ['Bratmobile', 'Pottymouth', 1993],
    ['Coltrane, John', 'Giant Steps', 1959],
];

// get and output the table
$myTable = Table::get($headers, $rows);

print $myTable;

// array of column headers
$headers = ['Artist', 'Title', 'Year'];

// array of arrays, one for each row in the table
$rows = [
    ['Bratmobile', 'Pottymouth', 1993],
    ['Coltrane, John', 'Giant Steps', 1959],
];

$myTable = Table::get($headers, $rows);


$data = [
    [
        'Artist' => 'Bratmobile',
        'Title' => 'Pottymouth',
        'Year' => 1993
    ],
    [
        'Artist' => 'Coltrane, John',
        'Title' => 'Giant Steps',
        'Year' => 1959
    ],
];

$myTable = Table::get($data);

$dsn = "mysql:host=<hostname>;dbname=<dbname>;charset=UTF8";
$pdo = new PDO($dsn, "<username>", "<password>");

$stmt = $pdo->query("SELECT * FROM albums");

$myTable = Table::get($stmt);

$albums = Album::all();

$myTable = Table::get($albums);

print Table::get($headers, $rows, TABLE_BORDER_STANDARD); // or
print Table::get($dataArray, TABLE_BORDER_STANDARD); // or
print Table::get($pdoStatement, TABLE_BORDER_STANDARD); // or
print Table::get($eloquentCollection, TABLE_BORDER_STANDARD);

print Table::get($headers, $rows, TABLE_BORDER_SOLID); // or
print Table::get($dataArray, TABLE_BORDER_SOLID); // or
print Table::get($pdoStatement, TABLE_BORDER_SOLID); // or
print Table::get($eloquentCollection, TABLE_BORDER_SOLID);

print Table::get($headers, $rows, TABLE_BORDER_DOUBLE); // or
print Table::get($dataArray, TABLE_BORDER_DOUBLE); // or
print Table::get($pdoStatement, TABLE_BORDER_DOUBLE); // or
print Table::get($eloquentCollection, TABLE_BORDER_DOUBLE);

$headers = ['Artist', 'Title', 'Year'];
$rows = [
    ['Bratmobile', 'Pottymouth', 1993],
    ['Coltrane, John', 'Giant Steps', 1959],
];

print Table::get($headers, $rows, TABLE_BORDER_STANDARD, [RIGHT, LEFT, CENTRE]);

$headers = ['id', 'some_json'];
$rows = [
    [1, json_encode(['artist' => 'Bratmobile', 'title' => 'Pottymouth'], JSON_PRETTY_PRINT)],
    [2, json_encode(['artist' => 'Coltrane, John', 'title' => 'Giant Steps'], JSON_PRETTY_PRINT)],
];

$myTable = Table::get($headers, $rows);
print $myTable;

$pottyMouth =<<<TXT
Pottymouth
label:\tKRS
yr:\t1993
rating:\t4.5
TXT;

$giantSteps =<<<TXT
Giant Steps
label:\tAtlantic
yr:\t1959
rating:\t5
TXT;

$headers = ['Artist', 'Title'];
$rows = [
    ['Bratmobile', $pottyMouth],
    ['Coltrane, John', $giantSteps],
];

$myTable = Table::get($headers, $rows);
print $myTable;