Php 仅第一行上的标题
我正在为一个网站项目构建一个表格视图,我已经工作了相当长的时间,在昨天晚上取得了一些重大突破。但是,仍然困扰该系统的一个问题是表视图中每隔一行的标题。是否有任何方法仅删除标题的回显?我试过这样做,但它总是坏:(Php 仅第一行上的标题,php,html,css,mysql,Php,Html,Css,Mysql,我正在为一个网站项目构建一个表格视图,我已经工作了相当长的时间,在昨天晚上取得了一些重大突破。但是,仍然困扰该系统的一个问题是表视图中每隔一行的标题。是否有任何方法仅删除标题的回显?我试过这样做,但它总是坏:( 您只需在循环时复制上面的所有“th”标记,这样它将只呈现一次。您的表应该是什么样子 首先是标题,然后是所有内容行?如果是,只需将回音放在while循环前面即可 对于TH来说,重要的是你把它们放在一个TR中,就像普通的TD一样。你在循环中包含了TH,这就是为什么它会一次又一次地显示。你
您只需在循环时复制上面的所有“th”标记,这样它将只呈现一次。您的表应该是什么样子
首先是标题,然后是所有内容行?如果是,只需将回音放在while循环前面即可
对于TH来说,重要的是你把它们放在一个TR中,就像普通的TD一样。你在循环中包含了TH
,这就是为什么它会一次又一次地显示。你应该在循环外回显你的TH
。类似这样的事情
<!DOCTYPE html>
<html>
<head>
<link href='style.css?lol=<?php echo time(); ?>' rel='stylesheet'
type='text/css'>
</head>
<body>
<?php
include_once("dbConnect.php");
if (isset($_GET["frompost"])) {
echo "<h3>Thank you for your scrim post! It's been tweeted by <a
href='http://twitter.com/scrimfinder'>ScrimFinder</a>.";
echo "<br>";
} else {
}
echo '<table cellspacing="0" cellpadding="7" width="1"><tr class="top">
<th>System</th>
<th>Region</th>
<th>Game</th>
<th>Match Type</th>
<th>Time</th>
<th>Time Zone</th>
<th>Date</th>
<th>Gamertag</th>
<th>Twitter</th>
</tr>';
$sql = "SELECT * FROM scrims ORDER BY id DESC LIMIT 30;";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0):
while ($row = mysqli_fetch_array($result) ) {
echo '
<tr><td><center>'.$row["system"].'</center></td><td class="grey">
<center>'.$row["region"].'</center></td> <td>
<center>'.$row["game"].'</center></td> <td class="grey">
<center>'.$row["matchtype"].'</center></td> <td>
<center>'.$row["time"].'</center></td> <td class="grey">
<center>'.$row["timezone"].'</center></td> <td>
<center>'.$row["date"].'</center></td> <td class="grey">
<center>'.$row["gamertag"].'</center></td> <td><center><a
href="http://www.twitter.com/'.$row['twitter'].'" target="_blank"><input
type="submit" value="Message '.$row['twitter'].'" class="button"></a>
</center></td> </tr> '; }
else:
echo "<tr><td colspan = '100'>NO RECORDS FOUND</td></tr>";
endif;
echo '</table>';
?>
在循环外部给出标题
的回音,在循环内部只回音行
。如果查询返回空怎么办?我们应该得到一个只有可用标题的空表吗?@Nikosgkogpoulos我编辑了我的答案,以检查是否返回空