<body>
    <header id="header" role="banner">
    </header>
    <div id="content" class="wrap">
        <main role="main">
            <section>
                <article id="main_article">
                <?php 
$headers = array('id', 'userid', 'department', 'courseid', 'fullname', 'category', 'category name', 'timeenrolled', 'timestarted', 'timecompleted');
echo "<h2>original data</h2>";
simpleHtmlTable($recordset, $headers);
echo "<h2>pivot on userid</h2>";
$data = Pivot::factory($recordset)->pivotOn(array('userid'))->addColumn(array('category name'), array('timecompleted'))->fetch();
if (empty($data)) {
    echo "Error: Pivot table not returned!";
} else {
    simpleHtmlTable($data, array('userid', 'fullname', 'department', 'timecompleted'));
}
?>
                </article>
            </section>
        </main>
    </div>
    <footer role="contentinfo">
        <?php 
echo $OUTPUT->footer();
?>
    </footer>
</body>
</html>
Example #2
0
    foreach (array_keys($data[0]) as $item) {
        echo "<td><b>{$item}<b></td>";
    }
    echo "</thead>";
    foreach ($data as $row) {
        echo "<tr>";
        foreach ($row as $item) {
            echo "<td>{$item}</td>";
        }
        echo "</tr>";
    }
    echo "</table>";
}
echo "<h2>original data</h2>";
simpleHtmlTable($recordset);
echo "<h2>pivot on 'host'</h2>";
$data = Pivot::factory($recordset)->pivotOn(array('host'))->addColumn(array('year', 'month'), array('users', 'clicks'))->fetch();
simpleHtmlTable($data);
echo "<h2>pivot on 'host' with totals</h2>";
$data = Pivot::factory($recordset)->pivotOn(array('host'))->addColumn(array('year', 'month'), array('users', 'clicks'))->fullTotal()->lineTotal()->fetch();
simpleHtmlTable($data);
echo "<h2>pivot on 'host' and 'country'</h2>";
$data = Pivot::factory($recordset)->pivotOn(array('host', 'country'))->addColumn(array('year', 'month'), array('users', 'clicks'))->fullTotal()->pivotTotal()->lineTotal()->fetch();
simpleHtmlTable($data);
echo "<h2>pivot on 'host' and 'country' with group count</h2>";
$data = Pivot::factory($recordset)->pivotOn(array('host', 'country'))->addColumn(array('year', 'month'), array('users', 'clicks', Pivot::count('count')))->fullTotal()->pivotTotal()->lineTotal()->fetch();
simpleHtmlTable($data);
echo "<h2>pivot on 'country' with group count</h2>";
$data = Pivot::factory($recordset)->pivotOn(array('host'))->addColumn(array('country'), array('year', Pivot::count('count')))->lineTotal()->fullTotal()->fetch();
simpleHtmlTable($data);
 public function render()
 {
     if (isset($this->dept_sums)) {
         //dept summary render code
         echo '<table>';
         echo '<tr>';
         echo '<th>Department</th>';
         echo '<th>Skill</th>';
         echo '<th>Time per Skill (Mins)</th>';
         echo '<th>Total Time (Mins)</th>';
         echo '</tr>';
         foreach ($this->dept_sums as $summary) {
             $categories = $summary->get_categories();
             $cat_count = count($categories);
             // set id to key of first
             // element
             $id = current(array_keys($categories));
             echo '<tr>';
             echo '<td rowspan="' . $cat_count . '">' . $summary->get_dept() . '</td>';
             echo '<td>' . $categories[$id] . '</td><td>' . round($summary->get_category_hours($id), 2) . '</td>';
             echo '<td rowspan="' . $cat_count . '">' . round($summary->get_dept_total(), 2) . '</td>';
             echo '</tr>';
             foreach ($categories as $cat_id => $cat_name) {
                 if ($cat_id != $id) {
                     echo '<tr><td>' . $cat_name . '</td><td>' . round($summary->get_category_hours($cat_id), 2) . '</td></tr>';
                 }
             }
         }
         echo '</table>';
         return;
     }
     if (!isset($this->record_set)) {
         $this->get_data();
     }
     $this->rows = simpleHtmlTable($this->record_set, $this->table_columns);
     $this->record_set->close();
 }