SIDEBAR
»
S
I
D
E
B
A
R
«
Creating Table from MySql
August 19th, 2009 by Mojtaba

Here is a PHP code in order to view table in HTML format from MySql database, As one knows you have to place this code in php tag (<?php … ?>) in order to execute it.

print "<TABLE BORDER=0 CELLPADDING=2>\n";
$fields = mysql_list_fields("DATABASENAME", "YOURSQLTABLENAME");
$columns = mysql_num_fields($fields);
print "<TR>";
for ($x = 0; $x < $columns;$x++ ) {
print "<TH>" . mysql_field_name($fields,$x) . "</TH>\n";
}
print "</TR>\n";
$sql = "SELECT * from YOURSQLTABLENAME";
$result = mysql_query($sql);
while ($obj = mysql_fetch_object($result,MYSQL_ASSOC)) {
print "<TR>";
foreach($obj as $val) {
print "<TD>" . $val . "</TD>";
}
print "</TR>\n";
}
echo "</TABLE>\n";


Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
»  Substance:WordPress   »  Style:Ahren Ahimsa
© 2010 Mojtabacazi.com . All right reserved