[英]Looping a table to display results in a row
I would like to display contents of a table that would be in a row. 我想显示一行中的表的内容。 as of now my codes generate it in a column, vertically.
到目前为止,我的代码在垂直的列中生成它。 How can I fix it so that it would be side-by-side when generated.
我如何解决它,使其在生成时可以并排放置。
or at least if it's more than 2 或至少大于2
2 columns maximum, and then another row for the other values then after 2 columns, another row. 最多2列,然后是另一行的其他值,然后是2列之后的另一行。
Please help me display both. 请帮助我同时显示两者。 So I can see which is better.
所以我看哪个更好。
Here is my code: 这是我的代码:
<table width="" cellpadding="3" cellspacing="0" border="0">
<?php
$qry="SELECT * FROM shipping";
$result= @mysql_query($qry);
while ($row=mysql_fetch_assoc($result)){
?>
<tr class="row_submit">
<td height="250px" width="300px"><center><label>
<input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="row[ship_name]") echo "checked";?> value="<?php echo $row['ship_name']; ?>">
<!--<img src="../paymentoptions/lbc.png" alt="LBC" class="picture" width="245px" style="margin:10px"/></label></td> -->
<?php echo '<img src="data:image/jpeg;base64,'.base64_encode( $row['ship_pic'] ).'" height="210px" width="245px" style="margin:10px"/>'; ?>
<td></td>
</tr>
<tr class="row_submit">
<td height="180px" width="300px"><p><?php echo $row['ship_desc']; ?><p>
<div id='price'> Additional ₱ <?php echo $row['ship_price']; ?></div></td>
<td></td>
<?php } ?>
</table>
This will display your data in rows of two columns each: 这将以两列的行显示数据:
<?php
echo "<table><tr>";
$i = 0;
while (...) {
if ($i > 0 && $i % 2 == 0) {
echo "</tr><tr>";
}
echo "<td>...</td>";
$i++;
}
echo "</tr></table>";
?>
Result: 结果:
***************
Item1 | Item2
Item3 | Item4
Item5 | Item6
.... | ....
***************
To display your data side-by-side, in one single row, it is much simpler: 要在一行中并排显示数据,它要简单得多:
<?php
echo "<table><tr>";
while (....) {
echo "<td>...</td>";
}
echo "</tr></table>";
?>
Result: 结果:
*****************************************************************************
Item1 | Item2 | Item3 | Item4 | Item5 | Item6 | .... | ItemN |
*****************************************************************************
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.