在PHP中的HTML表中显示查询结果
问题描述:
我需要在网页中显示表格。表中的数据来自数据库,我可以使用mysql php库查询。我正在寻找一个模板/示例如何提出一个漂亮的表(我不擅长前端设计)。
I need to display a table in a web page. The data from the table comes from database which I can query using mysql php library. I am looking for a template/example of how to come up with a nice looking table (I am not good at front end design).
任何链接/示例/参考
答
这是一个如何将MySQL表读入HTML表的示例。
Here is an example on how to read a MySQL table into a HTML table. And no, it does not look nice.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Read values from MySQL</title>
</head>
<body>
<?
mysql_connect($db_host,$db_user,$db_pw);
mysql_select_db($db_name);
?>
<table border="1">
<tbody>
<?
$result = mysql_query("SELECT firstname, lastname FROM persons")
OR die(mysql_error());
while($row = mysql_fetch_assoc($result)) {
echo '<tr><td>' . $row['firstname'] . '</td><td>' . $row['lastname'] . '</td></tr>';
}
?>
</tbody>
</table>
</body>
</html>