2014-10-02 76 views
0

我想显示连续的表中的内容。截至目前,我的代码以垂直方式在一列中生成它。我怎样才能修复它,以便它在生成时并排。循环显示一行中的结果

,或者如果它是至少2个以上

2最大列,然后另一行为其他值,则在2列,另一行。

请帮我展示两者。所以我可以看到哪个更好。

这里是我的代码:

<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> 

回答

1

这将在每两列行显示您的数据:

<?php 
echo "<table><tr>"; 
$i = 0; 
while (...) { 
    if ($i > 0 && $i % 2 == 0) { 
     echo "</tr><tr>"; 
    } 
    echo "<td>...</td>"; 
    $i++; 
} 
echo "</tr></table>"; 
?> 

结果:

*************** 
Item1 | Item2 
Item3 | Item4 
Item5 | Item6 
.... | .... 
*************** 

要显示数据并排,在一个单行中,它是很多简单:

<?php 
echo "<table><tr>"; 
while (....) { 
    echo "<td>...</td>"; 
} 
echo "</tr></table>"; 
?> 

结果:

***************************************************************************** 
Item1 | Item2 | Item3 | Item4 | Item5 | Item6 | .... | ItemN | 
***************************************************************************** 
+0

如何排队?感谢逻辑btw – 2014-10-02 02:36:21

+0

你是什么意思? – 2014-10-02 02:37:24