Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // This function displays data in tabular format
- function tableView($sql, $width, $table, $key, $title = null) {
- $result = mysqli_query($_SESSION['dbconn'],$sql);
- if (!$result) {
- $_SESSION['message'] = print message('warning','Query error!');
- return $_SESSION['message'];
- }
- $fieldcount = mysqli_num_fields($result);
- $html = "
- <div class='container'>
- <table class='table table-striped table-hover' style='max-width:" . $width . ";margin:auto'>
- <thead>
- <tr>";
- while ($field = mysqli_fetch_field($result)) {
- $html .= "<th>" . $field->name . "</th>";
- }
- $html .= "</tr>
- </thead>
- <tbody>";
- while ($row = mysqli_fetch_array($result)) {
- $html .= "<tr>";
- $i = 0;
- while ($i < $fieldcount) {
- $html .= "<td>";
- if ($i == 0) {
- $html .= "<a href='" . SITEHOME . "/pages/record.php?title=" . $title . "&table=" . $table . "&key=" . $key . "&value=" . $row[$i] . "'>" . $row[$i] . "</a>";
- } else {
- $html .= $row[$i];
- }
- $html .= "</td>";
- $i += 1;
- }
- $html .= "</tr>";
- }
- $html .= "
- </tbody>
- </table>
- </div>";
- return $html;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement