duanruoyu6675 2014-12-18 10:42
浏览 25
已采纳

使用PHP在三列html表中显示MySql表的三条记录

I Need to show three records of MySql table in three different column using php.My Query is

SELECT * FROM TABLE1 WHERE Id IN(1,2,3)

I want to show the result as here enter image description here

How can i Write LOOP for it?like

while(loop condition)
{
//what will go here?

}

UPDATE: First row fields will show in first column of html table and second record fields will display in second column and so on...I am not asking only show three records

  • 写回答

3条回答 默认 最新

  • dongye6377 2014-12-18 11:00
    关注

    OP saying, it's not so simple. But it is.

    So, you have 2 ways to do it.

    First. In this case, you are loop through on the 3 columns. Fetch the first row. This put all the data into a div. Class name is column_1. Do it for the other 3. Then floating the divs to left to each other.

    $i = 1;
    while($row = $db->fetch_row()) {
        ?>
    <div class="column_<?php echo $i; ?>">
        <div class="picture">
            <?php echo $row["image"]; ?>
        </div>
        <div class="description">
            <?php echo $row["desc"]; ?>
        </div>
        ... and so on...
    
    </div>
    <?php
        $i++;
    }
    

    Second one, when you first collect the data about 3 rows, and then put them into a table rows by row.

    <?php
        while($row = $db->fetch_row()) {
            $results[] = $row;
        }
    ?>
    <table>
        <tr>
            <td><?php echo $result[0]['image'] ?></td>
            <td><?php echo $result[1]['image'] ?></td>
            <td><?php echo $result[2]['image'] ?></td>
        </tr>
        <tr>
            <td><?php echo $result[0]['desc'] ?></td>
            <td><?php echo $result[1]['desc'] ?></td>
            <td><?php echo $result[2]['desc'] ?></td>
        </tr>
    
    </table>
    

    EDIT

    I forgot that, there is a third solution. You can just build the table empty, and then you can update the cells with an ajax call with jQuery.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程