2014-05-18 23 views
0

我的腳本基本上從我的數據庫加載數據,我不得不<br>某處,但它不會工作,因爲它是一個巨大的表。所以我需要格式化這個表,所以每10行有一個<br>有沒有可能在<br> CSS中每10個錶行?

<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>。當我嘗試它時,會留下一個巨大的空白空間,但在日期和比賽之間仍然沒有空間。

+1

是的。但你的代碼在哪裏? – JakeGould

+0

'爲'
'爲$ half-assed-question {print'平靜下來並細化出細節'; }' – coreyward

+1

如果你的意思是'

',那麼沒有。 '
'在HTML表格的''之間無效。雖然,你可以放置一個空行 - '​​ '。 –

回答

2

不太確定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個項目&然後做一些事情。在這種情況下,插入一個其中包含&nbsp;的行。

相關問題