function home() { global $S, $twig; $T = new dbTables($S); // Pass some info to getPageTopBottom method $h->title = "Insert Update"; // Goes in the <title></title> $h->banner = "<h1>Insert Update Test</h1>"; // becomes the <header> section // Add some local css to but a border and padding on the table $h->css = <<<EOF <style> #tbl * { padding: .5em; border: 1px solid black; } .odd { color: white; background-color: red; } .oddtr { background-color: green; } </style> EOF; list($top, $footer) = $S->getPageTopBottom($h); // create a table from the memberTable $inc = 0; // The maketable() callback function gets the current row and the row description. // This table has two fields in each row, 'First Name' and 'Last Name'. // The description looks like "<tr><td>First Name</td><td>Last Name</td></tr>" // for the first row. The $desc still has the field keys not the final values. // This callback uses a counter to determin which rows are odd. We take the value of the // first field in the row ($row['First Name'] and add a span around it. // We then change the <tr> into <tr class='oddtr'> in the description. // Note the arguments are passed by reference rather than value so we can modify the results. function callback(&$row, &$desc) { global $inc; if (!($inc++ % 2)) { $row['First Name'] = "<span class='odd'>" . $row['First Name'] . "</span>"; $desc = preg_replace('~<tr>~', "<tr class='oddtr'>", $desc); } $row['ID'] = "<a href='/edit/" . $row['ID'] . "'>" . $row['ID'] . "</a>"; } // We use the 'as' to give our column headers nice names otherwise they would be // 'fname' and 'lname'. $sql = "select rowid as ID, fname as 'First Name', lname as 'Last Name' from {$S->memberTable}"; // The second argument to the maketable method is an array with the following properties: // 'callback', 'callback2', 'footer'] 'attr'. // 'attr' is an assoc array that can has attributes for the <table> tag, // like 'id', 'title', 'class', 'style' etc. // 'callback2' has the final row with the keys replaced by the column values. 'callback2' // just has the &$desc argument. // 'footer' is a footer string $f = "<tfoot><tr><th colspan='2'>Footer goes here</th></tr><tfoot>"; list($tbl) = $T->maketable($sql, array('footer' => $f, 'callback' => callback, 'attr' => array('id' => 'tbl'))); // Use twig to render the first template echo $twig->render('route-1.template', array('top' => $top, 'footer' => $footer, 'tbl' => $tbl)); }
<?php // example5.php $_site = (require_once getenv("SITELOAD") . "/siteload.php"); ErrorClass::setNoEmailErrs(true); ErrorClass::setDevelopment(true); $S = new $_site->className($_site); $T = new dbTables($S); // Pass some info to getPageTopBottom method $h->title = "Example 5"; // Goes in the <title></title> $h->banner = "<h1>Example 5</h1>"; // becomes the <header> section // Add some local css to but a border and padding on the table $h->css = <<<EOF <style> main table * { padding: .5em; border: 1px solid black; } </style> EOF; list($top, $footer) = $S->getPageTopBottom($h); // create a table from the memberTable $sql = "select * from {$S->memberTable}"; list($tbl) = $T->maketable($sql); echo <<<EOF {$top} <main> <h3>Create a table from the members database table</h3> <p>The members table follows:</p>
list($top, $footer) = $S->getPageTopBottom($h); echo <<<EOF {$top} <form method="post"> First Name: <input type="text" name="fname" value="{$fname}"><br> Last Name : <input type="text" name="lname" value="{$lname}"><br> <input type="submit" value="Submit"> <input type="hidden" name="page" value="post"> <input type="hidden" name="id" value="{$id}"> </form> {$footer} EOF; exit; } START: $T = new dbTables($S); // Pass some info to getPageTopBottom method $h->title = "Insert Update"; // Goes in the <title></title> $h->banner = "<h1>Insert Update Test</h1>"; // becomes the <header> section // Add some local css to but a border and padding on the table $h->css = <<<EOF <style> #tbl * { padding: .5em; border: 1px solid black; } .odd { color: white; background-color: red;