我的脚本主要是从我的数据库加载数据,我必须 <br>
某个地方,但它不会工作,因为它是一张巨大的 table 。所以我需要格式化这个表,这样每 10 行就有一个 <br>
.
<table align="center" cellspacing="0" cellpadding="0">
<?php
$date = mysql_query("SELECT DISTINCT `date` FROM `matches`");
while($daterow = mysql_fetch_assoc($date)){
echo ' <tr>
<td style="width:60px; background-color:#000000;"><font color="#FFFFFF" style="font-size:11px">'.$daterow['date'].'</font></td>
</tr>
';
$query = mysql_query("SELECT hour, team1, team2, goalsteam1, goalsteam2, competition FROM `matches` WHERE `date`='". $daterow['date'] ."'");
while($row = mysql_fetch_array($query)){
$teamtest = mysql_query("SELECT teamname FROM `teams` WHERE `team`='".$row['team1']."'");
$teamtestrow = mysql_fetch_assoc($teamtest);
$hour = substr($row['hour'],0,5);
echo '
<tr class="teamtable">
<td style="width:60px; font-size:11px;">'.$hour.'</td>
<td style="width:145px; font-size:11px;">'.$teamrow['teamtest'].'</td>
<td style="width:15px; font-size:11px;">'.$row['goalsteam1'].'</td>
<td style="width:15px; font-size:11px;">'.$row['goalsteam2'].'</td>
<td style="width:145px; font-size:11px;">'.$row['team2'].'</td>
<td style="width:120; font-size:11px;">'.$row['competition'].'</td>
</tr>';
}
}
?>
</table>
或者只是 <br>
在每次约会之前。当我尝试时,它只会留下一个巨大的空白,但日期和匹配项之间仍然没有空格。
最佳答案
不太确定 CSS 是否可以处理这个问题。并且不清楚根据您共享的代码,您希望在哪里发生中断。但通常你会使用 modulus PHP 中的运算符将是一个好的开始。知道这也许对您有用:
<table align="center" cellspacing="0" cellpadding="0">
<?php
$date = mysql_query("SELECT DISTINCT `date` FROM `matches`");
$counter = 0;
while($daterow = mysql_fetch_assoc($date)){
echo ' <tr>
<td style="width:60px; background-color:#000000;"><font color="#FFFFFF" style="font-size:11px">'.$daterow['date'].'</font></td>
</tr>
';
$query = mysql_query("SELECT hour, team1, team2, goalsteam1, goalsteam2, competition FROM `matches` WHERE `date`='". $daterow['date'] ."'");
while($row = mysql_fetch_array($query)){
$teamtest = mysql_query("SELECT teamname FROM `teams` WHERE `team`='".$row['team1']."'");
$teamtestrow = mysql_fetch_assoc($teamtest);
$hour = substr($row['hour'],0,5);
echo '
<tr class="teamtable">
<td style="width:60px; font-size:11px;">'.$hour.'</td>
<td style="width:145px; font-size:11px;">'.$teamrow['teamtest'].'</td>
<td style="width:15px; font-size:11px;">'.$row['goalsteam1'].'</td>
<td style="width:15px; font-size:11px;">'.$row['goalsteam2'].'</td>
<td style="width:145px; font-size:11px;">'.$row['team2'].'</td>
<td style="width:120; font-size:11px;">'.$row['competition'].'</td>
</tr>';
$counter++;
// Do a modulus check.
if ($counter % 10 == 0) {
echo "<tr><td colspan="6"> </td></tr>";
}
}
}
?>
</table>
关键代码块是这样的:
$counter++;
// Do a modulus check.
if ($counter % 10 == 0) {
echo "<tr><td colspan="6"> </td></tr>";
}
在每个循环中,$counter
递增 1。在 if()
语句中使用模数运算符,我们检查每 10 个元素,然后做一些事情。在这种情况下,插入一个包含
的行。
关于php - 是否可以 <br>在 CSS 中每 10 个表格行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23717559/