Displaying Fields and Data of a MySQL Table
by Amrit HallanByteswoth.com
Thursday, 18th August 2005
We often have to view MySQL tables in a tabular form without the SQL query console. Sometimes you have to see what all fields are there in a MySQL table and what information they contain. The following piece of code presents to you a tabular format of your table and its contents.
<?php
$query="select * from table_name";
$result=mysql_query($query);
echo "<table border=1>";
echo "<tr>";
for($i=0;$i<mysql_num_fields($result);$i++)
{
echo "<th>";
echo mysql_field_name($result, $i);
echo "</th>";
}
while($row=mysql_fetch_row($result))
{
echo "<tr>";
for($j=0;$j<$i;$j++)
{
echo "<td>";
echo $row[$j];
echo "</td>";
}
echo "</tr>";
}
echo "</tr>";
echo "</table>";
?>
Options:
Printer Friendly
Email Friend
Amrit Hallan is a freelance web designer. For all web site development and web promotion needs, you can get in touch with him at amrit@bytesworth.com . For further details, visit http://www.bytesworth.com You can subscribe to his newsletter [BYTESWORTH REACHOUT] on Web Designing Tips & Tricks by sending a blank email at bytesworth-subscribe@topica.com.
