【问题标题】:Is it possible to <br> every 10 table rows in CSS?是否可以在 CSS 中每 10 个表格行 <be> ?
【发布时间】:2018-06-01 23:39:54
【问题描述】:

我的脚本基本上从我的数据库中加载数据,我必须在某个地方 &lt;br&gt; 但它不会工作,因为它是一个巨大的表。所以我需要格式化这个表,这样每 10 行就有一个&lt;br&gt;

<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>

或者只是在每个日期之前&lt;br&gt;。当我尝试时,它只会留下一个巨大的空白空间,但日期和匹配项之间仍然没有空格。

【问题讨论】:

  • 是的。但是你的代码在哪里?
  • for '&lt;br&gt;' in $half-assed-question { print 'calm down and spell out the details'; }
  • 如果你的意思是&lt;table&gt;,那么没有。 &lt;br&gt;s 在 HTML 表格的 &lt;tr&gt;s 之间无效。不过,您可以放置​​一个空行——&lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
  • 是的..刚刚发现我可以放置一个空白行.. ty..
  • 嗯... HTML 不是 CSS。这个问题与 CSS 无关。

标签: php css mysql html-table


【解决方案1】:

不太确定 CSS 是否可以处理这个问题。并且不清楚根据您共享的代码您希望在哪里发生中断。但一般来说,在 PHP 中使用 modulus 运算符会是一个好的开始。知道也许这对你有用:

<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">&nbsp;</td></tr>";
                }
            }
        }
    ?>  
</table>

关键代码块是这样的:

$counter++;
// Do a modulus check.
if ($counter % 10 == 0) {
    echo "<tr><td colspan="6">&nbsp;</td></tr>";
}

在每个循环中,$counter 递增 1。使用 if() 语句中的模运算符,我们每隔 10 个项目检查一次,然后做一些事情。在这种情况下,插入一行,其中包含 &amp;nbsp;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-16
    • 1970-01-01
    • 1970-01-01
    • 2018-07-30
    • 1970-01-01
    • 2023-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多