Posted By

ginoplusio on 01/25/10


Tagged

mysql php html recordset


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ginoplusio


MYSQL Recordset to HTML table


 / Published in: PHP
 

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

  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. }

Report this snippet  

You need to login to post a comment.