【问题标题】:Looping a table to display results in a row循环表格以在一行中显示结果
【发布时间】:2023-03-13 23:13:01
【问题描述】:

我想在一行中显示表格的内容。截至目前,我的代码在垂直列中生成它。如何修复它,以便在生成时并排显示。

或者至少超过 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>

【问题讨论】:

    标签: php mysql sql loops html-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  |  
    *****************************************************************************
    

    【讨论】:

    • 排队是什么意思?
    猜你喜欢
    • 2014-12-23
    • 2015-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-19
    • 2016-08-29
    • 1970-01-01
    • 2018-08-09
    相关资源
    最近更新 更多