Advertisement
dbcalmada

policies.table_view

Mar 27th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. <?php
  2. // This function displays data in tabular format
  3.  
  4. function tableView($sql, $width, $table, $key, $title = null) {
  5.     $result = mysqli_query($_SESSION['dbconn'],$sql);
  6.    
  7.     if (!$result) {
  8.         $_SESSION['message'] = print message('warning','Query error!');
  9.         return $_SESSION['message'];
  10.     }
  11.    
  12.     $fieldcount = mysqli_num_fields($result);
  13.  
  14.     $html = "  
  15.  
  16.     <div class='container'>
  17.     <table class='table table-striped table-hover' style='max-width:" . $width . ";margin:auto'>
  18.         <thead>
  19.             <tr>";
  20.            
  21.             while ($field = mysqli_fetch_field($result)) {
  22.                 $html .= "<th>" . $field->name . "</th>";
  23.             }
  24.            
  25.             $html .= "</tr>
  26.         </thead>
  27.         <tbody>";
  28.        
  29.             while ($row = mysqli_fetch_array($result)) {
  30.                 $html .= "<tr>";
  31.                     $i = 0;
  32.                     while ($i < $fieldcount) {
  33.                         $html .= "<td>";
  34.                                 if ($i == 0) {
  35.                                     $html .= "<a href='" . SITEHOME . "/pages/record.php?title=" . $title . "&table=" . $table . "&key=" . $key . "&value=" . $row[$i] . "'>" . $row[$i] . "</a>";
  36.                                 } else {
  37.                                     $html .= $row[$i];
  38.                                 }
  39.                         $html .= "</td>";
  40.                         $i += 1;
  41.                     }
  42.                 $html .= "</tr>";
  43.             }
  44.        
  45.         $html .= "
  46.         </tbody>
  47.     </table>
  48.     </div>";
  49.    
  50.     return $html;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement