2013-09-30 21 views
0

我當前使用SQL結果此HTML表格來填補它使用「好」 HTML表的SQL結果(PHP)

<table> 
<table border="1"> 
    <tr> 

     <th>Username</th> 
     <th>holid</th> 
     <th>Start date</th> 
     <th>end date</th> 
     <th>Work days off</th> 


    </tr> 
    <?php foreach($rows as $row): ?> 
    <table border="1"> 
     <tr> 
      <td><?php echo htmlentities($row['username'], ENT_QUOTES, 'UTF-8');?></td> 
      <td><?php echo htmlentities($row['starthol'], ENT_QUOTES, 'UTF-8'); ?></td> 
      <td><?php echo htmlentities($row['endhol'], ENT_QUOTES, 'UTF-8'); ?></td> 
      <td><?php echo htmlentities($row['days'], ENT_QUOTES, 'UTF-8'); ?></td> 
      <td><a href="#">Approve</a></td> 
      <td><a href="#">Reject</a></td> 

     </tr> 
    <?php endforeach; ?> 
</table> 

這工作得很好,一切,但該表是非常混亂和標題都出來了線。有沒有簡單的方法來使這個更清潔(PHP初學者)。

+0

該問題發出的信號表明你也是一個HTML初學者。我首先閱讀一些關於這方面的教程。爲此,你不應該爲從DB讀取的每一行創建一個單獨的表格,只是'',並且它們裏面有什麼...... – ppeterka

+0

你正在創建很多

的,你應該檢查什麼樣的HTML在此之後呈現。 –

回答

2

這是額外的表標記刪除編碼,並參閱下面的CSS編碼。

<table border="1"> 
<tr> 

    <th>Username</th> 
    <th>holid</th> 
    <th>Start date</th> 
    <th>end date</th> 
    <th>Work days off</th> 


</tr> 
<?php foreach($rows as $row): ?> 

    <tr> 
     <td><?php echo htmlentities($row['username'], ENT_QUOTES, 'UTF-8');?></td> 
     <td><?php echo htmlentities($row['starthol'], ENT_QUOTES, 'UTF-8'); ?></td> 
     <td><?php echo htmlentities($row['endhol'], ENT_QUOTES, 'UTF-8'); ?></td> 
     <td><?php echo htmlentities($row['days'], ENT_QUOTES, 'UTF-8'); ?></td> 
     <td><a href="#">Approve</a></td> 
     <td><a href="#">Reject</a></td> 

    </tr> 
<?php endforeach; ?> 
</table> 


/*css styles*/ 

table { 

    border-collapse: collapse; 
} 
/* Zebra striping */ 
tr:nth-of-type(odd) { 
    background: #eee; 
} 
th { 
    background: #333; 
    color: white; 
    font-weight: bold; 
} 
td, th { 
    padding: 6px; 
    border: 1px solid #ccc; 
    text-align: left; 
} 
+0

謝謝,我現在明白了。這是扔我的循環:) – Programatt

1

刪除第二個<table border="1">,低於foreach指令的一個。

編輯:也是第一個。每個<table>標籤應該有一個相應的</table>(即去的所有標籤HTML!)

另外,儘量與<td>的比賽<th>秒。現在有5個<th> s,每行有6個<td> s。