douqiang5933 2015-06-06 09:32
浏览 334

如何在HTML表中显示MySQL查询的结果

I am trying to display the records that are returned from a query in a html table. So when the query is processed the 1st record in the mysql database table (containing the image and the song title) will be displayed in the first block in the html table (Row 1, Column1) below and the 2nd record will be displayed in the second block of the table (Row 1, Column2) and so on, but after three records have been displayed. I would want a new row in the table to be generated

HTML table output should look like this below:

           column 1     column 2     column 3
         -----------------------------------------
         | Image1      | Image2      | Image3      |
row 1 -> | song title1 | song title2 | song title3 |      
         ------------------------------------------
         | Image 4     | Image 5     | Image6      |
row 2 -> | Song title4 | song title5 | song title6 |
         ------------------------------------------

And here is the structure of the table in my mysql database:

search
         ------------------------------
        |  Id   |  image |    song     |
         ------------------------------
row 1-> |   1   | image1 | song title1 |
         ------------------------------
row 2-> |   2   | image2 | song title2 | 
         ------------------------------
row 3-> |   3   | image3 | song title3 |
         ------------------------------


row 4...

So far I can only display the results in a table but I don't know how to structure the table in the format of the html table example I gave above Here is the code I have so far:

while($row = mysql_fetch_assoc($queryset)) {
                        $id = $row['id'];
                        $image = $row['image'];
                        $song = $row['song'];

                        echo '<table style="width:100%">
                                  <tr>

                                    <td>

                                        $image
                                        <br>
                                        $song 

                                    </td>
                                  </tr>
                               </table>';





                    }

I apologies in advance if I have made any mistakes/errors or if I have wasted you time, I'm kind of new to this whole thing.?

  • 写回答

6条回答 默认 最新

  • doutui2016 2015-06-06 09:38
    关注
    <table>
    
    <?php 
    while($row = mysql_fetch_assoc($queryset)) {
    ?>
    <tr>
    <td><?php echo $row["id"]; ?></td>
    <td><?php echo $row["image"]; ?></td>
    <td><?php echo $row["song"]; ?></td>
    </tr>
    <?php
    }
    ?>
    </table>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘