标题只在第一行

时间:2018-02-13 07:13:11

标签: php html css mysql

我正在为一个我已经工作了很长一段时间的网站项目构建一个表格视图,并在昨晚取得了一些重大突破。但是,仍然困扰着这个系统的问题是表视图的每一行的标题。反正只是为了删除标题的回声?我试过这样做,但它一直在破坏:( http://www.scrimfinder.net

<!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">  </tr> ';  
$sql = "SELECT * FROM scrims ORDER BY id DESC LIMIT 30;";  
$result = mysqli_query($conn, $sql);  
while ($row = mysqli_fetch_array($result)) {    
echo '        
<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>          <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>  ';  } echo '</table>';
?>

</body>
</html>

3 个答案:

答案 0 :(得分:1)

您在循环中加入了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>';
 ?>

答案 1 :(得分:0)

您只需要复制所有&#39;&#39; while循环上面的标签,所以它只渲染一次。

答案 2 :(得分:0)

你的桌子怎么样?

首先是标题然后是所有内容行?如果是,只需将回声放在while循环前面

对于那些你把它们放到TR中的重要性,就像正常的TD一样。