我有一個PHP數組,每行產生四列表。我需要修改我的PHP,所以我有八列而不是四列。強制PHP循環顯示每行8列
例如。電流輸出看起來像:
COL 1 COL 2 COL 3 COL 4
COL 5 COL 6 COL 7 COL 8
COL 9 COL 10 COL 11 COL 12
COL 13 COL 14 COL 15 COL 16
但我需要它看起來像這樣:
COL 1 COL 2 COL 3 COL 4 COL 5 COL 6 COL 7 COL 8
COL 9 COL 10 COL 11 COL 12 COL 13 COL 14 COL 15 COL 16
關於前一個問題我問我是否可以通過CSS/HTML做到這一點。強烈建議我修改我的PHP代碼。我收到了僞代碼來執行此操作,但我無法使其工作。邏輯如下:
if($counter % 2 == 0)
output startting <tr> tag
output the four <td> tags with data
if(($counter +1) % 2 == 0)
output closing <tr> tag
這裏是我當前的代碼:
<form>
<table>
<?php $counter = 0;
while ($counter < 20) :
$item = $set[$counter]
if($counter % 2 == 0) ?>
<tr class="q<?php echo $counter; ?>">
<td><a class="question" href="<?php echo $item['qurl'] ?>');"><?php echo $item['q'] ?></a></td>
<td><input class="a1" type="text" name="a1" maxlength="3" size="3" /></td>
<td><input class="a2" type="text" name="a2" maxlength="3" size="3" /></td>
<td><input class="submit submit-<?php echo $counter; ?>" type="submit" value="Submit" /></td>
<?php if(($counter +1) % 2 == 0) ?>
</tr>
<?php $counter++; ?>
<?php endwhile; ?>
</table>
</form>
我是初學者所以請原諒我的新手嘗試。提前致謝。
你應該更新你原來的問題,而不是創建一個新的。 http://stackoverflow.com/questions/11587360/force-html-table-to-have-eight-columns-on-a-single-row/11587391#11587391 – 2012-07-20 23:21:28
很抱歉。我是新來的。我以前的問題是關於編輯HTML/CSS,所以我認爲我應該爲PHP創建一個新的。 – Derrick 2012-07-20 23:23:01
是的,我想,它不是一回事,而是繼續從你之前談論的問題,不知道SO規則是什麼。 – 2012-07-20 23:23:58