Friday, April 22, 2016

Dump an SQL query

This is specifically mysqli php dump.  Saved my some time in formatting outputs of internal scripts.  Not really suitable for front end dev.


 function printTable(&$result)  
 {  
      $finfo = $result->fetch_fields();  
      echo '<table class="striped">' . "\n";  
      echo '<tr class="header">' . "\n";  
      foreach ($finfo as $val) {  
           echo "<td>".$val->name."</td>\n";  
      }  
      echo "</tr>\n";  
      while($row = $result->fetch_assoc()) {  
           echo "<tr>";  
           foreach ($row as $col) {  
                echo "<td>".$col."</td>";  
           }  
           echo "</tr>\n";  
      }  
      echo "</table>\n";  
      $result->free();  
 }