MySQL Query to HTML Table


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

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


Copy this code and paste it in your HTML
  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);

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.