我试图以两列表格格式显示一些图像和单选按钮。
它应该在每两个图像之后开始一个新行,相反,即使计数器小于2($ i == $ c),行也会结束
我得到了:
<td align="center" bgcolor=#CCCCCC>
<img src=http://web.com/7534560_2.jpg width='200' height='125' />
<br>Primary Image<input type="radio" name="primary" id="primary"
value=http://web.com/7534560_2.jpg />
**</td></tr>**
<td align="center" bgcolor=#CCCCCC>
<img src=http://web.com/7534560_3.jpg width='200' height='125' />
<br>Primary Image<input type="radio" name="primary" id="primary"
value=http://web.com/7534560_3.jpg />
而不是预期的:
<td align="center" bgcolor=#CCCCCC>
<img src=http://web.com/7534560_2.jpg width='200' height='125' />
<br>Primary Image<input type="radio" name="primary" id="primary"
value=http://web.com/7534560_2.jpg />
**</td>**
<td align="center" bgcolor=#CCCCCC>
<img src=http://web.com/7534560_3.jpg width='200' height='125' />
<br>Primary Image<input type="radio" name="primary" id="primary"
value=http://web.com/7534560_3.jpg />
以下是代码:
<?php
$iq = 2; // first image index offset
$c = '2'; // number of cells in a row
$i = 0; // counter
while ($image_qty + 1 > $iq) {
if ($i==0) {
echo '<tr>';
}
echo '<td align="center" bgcolor=#CCCCCC>';
$image_url = substr($image_url, 0, -4);
$image_url = $image_url . "_$iq" . ".jpg";
echo "<img src=$image_url width='200' height='125' /><br>";
echo 'Primary Image<input type="radio" name="primary" id="primary" value=' . $image_url .' />';
echo '</td>';
$image_url = $image_url_org; // reset image value
$iq++; // increment image number
$i++; // increment cell counter
if ($i == $c) // if number of cells at 2 end row
{
echo '</tr>';
$i = 0;
}
if ($i > 0 ) // if cells remaining less than 2
{
echo '</tr>';
}
}
?>