MySQLi convert a result set to an HTML table


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function getHtmlTable($rs){
  2. // receive a record set and print
  3. // it into an html table
  4. $out = '<table>';
  5. while ($field = $rs->fetch_field()) $out .= "<th>".$field->name."</th>";
  6. while ($linea = $rs->fetch_assoc()) {
  7. $out .= "<tr>";
  8. foreach ($linea as $valor_col) $out .= '<td>'.$valor_col.'</td>';
  9. $out .= "</tr>";
  10. }
  11. $out .= "</table>";
  12. return $out;
  13. }

URL: http://www.barattalo.it/2010/01/29/10-php-usefull-functions-for-mysqli-improved-stuff/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.