Jump to content


Photo

Outputting and Entire Mysql Table as an HTML table


  • Please log in to reply
2 replies to this topic

#1 gladiator83x

gladiator83x
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 25 July 2006 - 04:55 AM

Hi All,

I was just wondering if someone could assist me in outputting one of my Mysql tables as an Html table.
I believe that I have to use one of the SHOW TABLE commands that mysql offers.

I was thinking:

$query="SHOW TABLE_NAME";
$result="mysql_query($query)";

Any suggestions?

#2 manichean

manichean
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 25 July 2006 - 05:47 AM

Hello gladiator83x,

Have a look here
http://www.biorust.c.../detail/221/en/

cheers

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 25 July 2006 - 09:12 AM

try this
<?php
$result = mysql_query("SELECT * FROM tablename");

echo "<TABLE border='1' cellpadding='4'>\n";

// column headings
      echo "<tr>\n";
      while ($fld = mysql_fetch_field ($result)) {
               echo "<th>{$fld->name}</th>\n";
      }
      echo "</tr>\n";
      

// list data
      while ($row = mysql_fetch_row($result)) {
      echo "<tr>\n";
      foreach ($row as $field) {
               echo "<td>$field</td>\n";
      }
      echo "</tr>\n";
}

echo "</TABLE>\n";
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users