简体   繁体   English

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

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

I'm using the following code to display rows from a MySQL table in a html table.我正在使用以下代码在 html 表中显示 MySQL 表中的行。 I've already defined the table headers in the php - please can anyone advise how I modify the code to stop it bringing the MySQL column headings into the table as well?我已经在 php 中定义了表标题 - 请有人建议我如何修改代码以阻止它也将 MySQL 列标题带入表中?

Currently, it's displaying the table headings (row 1), then the MySQL column headings (row 2), before the records begin being displayed on row 3.当前,它先显示表标题(第 1 行),然后是 MySQL 列标题(第 2 行),然后记录开始显示在第 3 行。

I've tried using -N at various points in the code to suppress the column headings, but it just throws an error.我曾尝试在代码中的各个点使用 -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);

?>

You are looping over the data retrieved by from the DB.您正在遍历从数据库检索到的数据。 So the records must exist in the database.所以记录必须存在于数据库中。 If you still want to ignore the data如果您仍然想忽略数据

$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