dongshui2254 2013-06-07 09:35
浏览 22

PHP中的MySql表格式

So this PHP Code would print all the table data from my database on a Web-Page.

<?php
$hostname = '127.0.0.1:3306';        
$dbname   = 'login'; // Your database name.
$username = 'root';             // Your database username.
$password = '';                 // Your database password. If your database has no password, leave it empty.

mysql_connect($hostname, $username, $password) or DIE('Connection to host is failed, perhaps the service is down!');
mysql_select_db($dbname) or DIE('Database name is not available!');
$query="SELECT * FROM markers";
$result=mysql_query($query);

$fields_num = mysql_num_fields($result);
echo "<table border='2'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result);
    echo "<td>{$field->name}</td></div>";
}
echo "</tr>
";
// printing table rows

while($row = mysql_fetch_row($result))

{
    echo "<table>";
    echo "<tr>";

    echo "<td>$row[0]</td>";
    echo "<td>$row[1]</td>";
    echo "<td>$row[2]</td>";
    echo "<td>$row[3]</td>";
    echo "</tr>
";
    echo "</table></div>";

}
?>

But what Essentially it's doing is that. It's not properly formatted.It comes like this.

Unformatted Table

What I wanted to do Is to bring this table exactly in the center of the web-page, Give it some fancy borders(curvy edges, Great fonts.)

  • 写回答

6条回答 默认 最新

  • duanpao4172 2013-06-07 09:40
    关注

    You're creating a new table for every iteration through rows. Move the <table> tags outside of the loop.

    评论

报告相同问题?

悬赏问题

  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计