Posted By

cubit on 12/14/07


Tagged

php html tables


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

vali29
basicmagic
willcodeforfood
joethermal
WaxWing


MySQL Query to HTML Table


 / Published in: PHP
 

URL: http://www.thescripts.com/forum/thread276.html

Not mine. Changed from the original it to suit my needs.

  1. function _mysql_result_all($result, $tableFeatures="border='1'",$nodata=" ") {
  2. $tableDebug .= "<!--Debugging output for SQL query-->\n\n";
  3. echo "<table $tableFeatures>\n\n";
  4. $noFields = mysql_num_fields($result);
  5. echo "<tr>\n";
  6. for ($i = 0; $i < $noFields; $i++) {
  7. $field = mysql_field_name($result, $i);
  8. echo "\t<th>$field</th>\n";
  9. }
  10. while ($r = mysql_fetch_row($result)) {
  11. echo "<tr>\n";
  12. foreach ($r as $column) {
  13. echo "\t<td>";
  14. if ($column == NULL) {
  15. echo "$nodata";
  16. } else {
  17. echo $column;
  18. }
  19. echo "</td>\n";
  20. }
  21. echo "</tr>\n";
  22. }
  23. echo "</table>\n\n";
  24. echo "<!--End debug from SQL query-->\n\n";
  25. return $tableDebug;
  26. }
  27.  
  28.  
  29. _mysql_result_all($result);

Report this snippet  

You need to login to post a comment.