繁体   English   中英

在 html 表中显示 MySQL 记录时如何抑制列标题

[英]How to suppress column headings when displaying MySQL records in a html table

我正在使用以下代码在 html 表中显示 MySQL 表中的行。 我已经在 php 中定义了表标题 - 请有人建议我如何修改代码以阻止它也将 MySQL 列标题带入表中?

当前,它先显示表标题(第 1 行),然后是 MySQL 列标题(第 2 行),然后记录开始显示在第 3 行。

我曾尝试在代码中的各个点使用 -N 来抑制列标题,但它只会引发错误。

<?php

// Create connection
$con = mysql_connect("localhost","xxxxxxxxxx","xxxxxxxxx");
// Check connection
if (!$con) {
    die("Connection failed: " . mysql_error());
} 

mysql_select_db("xxxxxxxxxxxx",$con);
$sql = "SELECT * FROM SiteList";
$myData = mysql_query($sql,$con);
echo "<table border=1>
<tr>
<th>ID</th>
<th>Site_Name</th>
<th>Weather_Forecast</th>
<th>Forecast_Date</th>
<th>Forecast_Time</th>
<th>Further_Information_about_This_Site</th>
</tr>";
while($record = mysql_fetch_array($myData)) {
echo "<tr>";
echo "<td>" . $record['ID'] . "</td>";
echo "<td>" . $record['Site_Name'] . "</td>";
echo "<td>" . $record['Weather_Forecast'] . "</td>";
echo "<td>" . $record['Forecast_Date'] . "</td>";
echo "<td>" . $record['Forecast_Time'] . "</td>";
echo "<td>" . $record['Further_Information_about_This_Site'] . "</td>";
echo "</tr>";
}

echo "</table>";

mysql_close($con);

?>

您正在遍历从数据库检索到的数据。 所以记录必须存在于数据库中。 如果您仍然想忽略数据

$skip = 0; // declare coutner
while($record = mysql_fetch_array($myData)) {

if ($skip != 0){ // skip on first loop
echo "<tr>";
echo "<td>" . $record['ID'] . "</td>";
echo "<td>" . $record['Site_Name'] . "</td>";
echo "<td>" . $record['Weather_Forecast'] . "</td>";
echo "<td>" . $record['Forecast_Date'] . "</td>";
echo "<td>" . $record['Forecast_Time'] . "</td>";
echo "<td>" . $record['Further_Information_about_This_Site'] . "</td>";
echo "</tr>";
 }

$skip++; // increment counter

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM