MYSQL Recordset to HTML table


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



Copy this code and paste it in your HTML
  1. function getHtmlTable($result){
  2. // receive a record set and print
  3. // it into an html table
  4. $out = '<table>';
  5. for($i = 0; $i < mysql_num_fields($result); $i++){
  6. $aux = mysql_field_name($result, $i);
  7. $out .= "<th>".$aux."</th>";
  8. }
  9. while ($linea = mysql_fetch_array($result, MYSQL_ASSOC)) {
  10. $out .= "<tr>";
  11. foreach ($linea as $valor_col) $out .= '<td>'.$valor_col.'</td>';
  12. $out .= "</tr>";
  13. }
  14. $out .= "</table>";
  15. return $out;
  16. }

URL: http://www.barattalo.it/2010/01/25/10-php-usefull-functions-for-mysql-stuff/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.