Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Generate output tables from MySQL

Codes here !

Moderators: macek, egami, gesf

Generate output tables from MySQL

Postby ashz » Sun Dec 15, 2002 4:01 am

Hi,

The script below print a content of the MySQL database. The output print a record in a row and when the record finished it prints the next record below it and etc.

How can I generate an automatic table (separation between the records) so I will receive a nice output.

Thanks.

Script:
if ($rowsFound > 0)
{
while ($row = @ mysql_fetch_array($result))
{
print 'ID: '. $row["ID"]. ' ';
#echo "<br><br>\n";
print 'name: '. $row["name"]. ' ';
# echo "<br><br>\n";
print 'gen: '. $row["gen"]. ' ';
echo "<br><br>\n";
}
}
ashz
New php-forum User
New php-forum User
 
Posts: 14
Joined: Thu Oct 31, 2002 7:40 am

Postby webwired » Sun Dec 15, 2002 10:29 pm

I don't if I am sure about what you are asking, but if I'm right, here this should help.
Code: Select all
$query = mysql_query("SELECT * FROM `yourtable` WHERE 1");
while ($row  =  mysql_fetch_array($query))
      {
        $ID=$row["ID"];
        $name=$row["name"];
        $gen=$row["gen"];

print"<html>\n";
print"<head>\n";
print"</head>\n";
print"<body>\n";
print"<center>\n";
print"<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\">\n";
print"  <tr>\n";
print"    <td>&nbsp;$ID</td>\n";
print"    <td>&nbsp;$name</td>\n";
print"    <td>&nbsp;$gen</td>\n";
print"  </tr>\n";
print"</table>\n";
print"</center>\n";
print"</body>\n";
print"</html>\n";
    }
?>
User avatar
webwired
New php-forum User
New php-forum User
 
Posts: 26
Joined: Sat Nov 23, 2002 5:20 pm
Location: St. Louis, Missouri

Postby ashz » Mon Dec 16, 2002 2:28 am

Thanks for the code and how can I add lines so it will look like excel sheet.

thanks again
ashz
New php-forum User
New php-forum User
 
Posts: 14
Joined: Thu Oct 31, 2002 7:40 am

Postby webwired » Tue Dec 17, 2002 10:27 pm

Just make that border=1
User avatar
webwired
New php-forum User
New php-forum User
 
Posts: 26
Joined: Sat Nov 23, 2002 5:20 pm
Location: St. Louis, Missouri


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.