<small id='BDsrP'></small><noframes id='BDsrP'>

    <tfoot id='BDsrP'></tfoot>
      <bdo id='BDsrP'></bdo><ul id='BDsrP'></ul>
        <i id='BDsrP'><tr id='BDsrP'><dt id='BDsrP'><q id='BDsrP'><span id='BDsrP'><b id='BDsrP'><form id='BDsrP'><ins id='BDsrP'></ins><ul id='BDsrP'></ul><sub id='BDsrP'></sub></form><legend id='BDsrP'></legend><bdo id='BDsrP'><pre id='BDsrP'><center id='BDsrP'></center></pre></bdo></b><th id='BDsrP'></th></span></q></dt></tr></i><div id='BDsrP'><tfoot id='BDsrP'></tfoot><dl id='BDsrP'><fieldset id='BDsrP'></fieldset></dl></div>

        <legend id='BDsrP'><style id='BDsrP'><dir id='BDsrP'><q id='BDsrP'></q></dir></style></legend>
      1. 用 PHP 创建动态表

        时间:2023-10-04
      2. <legend id='yVySh'><style id='yVySh'><dir id='yVySh'><q id='yVySh'></q></dir></style></legend>
            1. <tfoot id='yVySh'></tfoot>
            2. <small id='yVySh'></small><noframes id='yVySh'>

                <bdo id='yVySh'></bdo><ul id='yVySh'></ul>

                  <tbody id='yVySh'></tbody>

                <i id='yVySh'><tr id='yVySh'><dt id='yVySh'><q id='yVySh'><span id='yVySh'><b id='yVySh'><form id='yVySh'><ins id='yVySh'></ins><ul id='yVySh'></ul><sub id='yVySh'></sub></form><legend id='yVySh'></legend><bdo id='yVySh'><pre id='yVySh'><center id='yVySh'></center></pre></bdo></b><th id='yVySh'></th></span></q></dt></tr></i><div id='yVySh'><tfoot id='yVySh'></tfoot><dl id='yVySh'><fieldset id='yVySh'></fieldset></dl></div>
                  本文介绍了用 PHP 创建动态表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试使用 PHP 制作动态表.我有一个页面显示数据库中的所有图片.我只需要该表为 5 列.如果返回的图片超过 5 张,则应创建一个新行,其余图片将继续显示.

                  I'm trying to make a dynamic table with PHP. I have a page which displays all the pictures from a database. I need the table to be of 5 columns only. If more than 5 pictures are returned, it should create a new row and the displaying of the rest of the pics would continue.

                  有人可以帮忙吗?

                  代码在这里:主页中的代码:-

                  Codes go here: Code in the main page:-

                      <table>
                      <?php
                          $all_pics_rs=get_all_pics();
                          while($pic_info=mysql_fetch_array($all_pics_rs)){
                          echo "<td><img src='".$pic_info['picture']."' height='300px' width='400px' /></td>";
                              } 
                  ?>
                  </table>
                  

                  get_all_pics() 函数:

                  The get_all_pics() function:

                  $all_pics_q="SELECT * FROM pics";
                          $all_pics_rs=mysql_query($all_pics_q,$connection1);
                          if(!$all_pics_rs){
                              die("Database query failed: ".mysql_error());
                          }
                          return $all_pics_rs;
                  

                  此代码正在创建单行.我想不出如何获得多行...... !!

                  This code is creating a single row. I can't think of how I can get multiple rows ... !!

                  推荐答案

                  $maxcols = 5;
                  $i = 0;
                  
                  //Open the table and its first row
                  echo "<table>";
                  echo "<tr>";
                  while ($image = mysql_fetch_assoc($images_rs)) {
                  
                      if ($i == $maxcols) {
                          $i = 0;
                          echo "</tr><tr>";
                      }
                  
                      echo "<td><img src="" . $image['src'] . "" /></td>";
                  
                      $i++;
                  
                  }
                  
                  //Add empty <td>'s to even up the amount of cells in a row:
                  while ($i <= $maxcols) {
                      echo "<td>&nbsp;</td>";
                      $i++;
                  }
                  
                  //Close the table row and the table
                  echo "</tr>";
                  echo "</table>";
                  

                  我还没有测试过,但我的疯狂猜测是这样的.只需使用图像循环浏览数据集,只要您还没有制作 5 个 <td>,就添加一个.到达 5 后,关闭该行并创建一个新行.

                  I haven't tested it yet but my wild guess is something like that. Just cycle through your dataset with the images and as long as you didn't make 5 <td>'s yet, add one. Once you reach 5, close the row and create a new row.

                  这个脚本应该给你类似下面的东西.这显然取决于您拥有的图像数量,我假设 5(在 $maxcols 中定义)是您想要连续显示的最大图像数量.

                  This script is supposed to give you something like the following. It obviously depends on how many images you have and I assumed that 5 (defined it in $maxcols) was the maximum number of images you want to display in a row.

                  <table>
                      <tr>
                          <td><img src="image1.jpg" /></td>
                          <td><img src="image1.jpg" /></td>
                          <td><img src="image1.jpg" /></td>
                          <td><img src="image1.jpg" /></td>
                          <td><img src="image1.jpg" /></td>
                      </tr>
                      <tr>
                          <td><img src="image1.jpg" /></td>
                          <td><img src="image1.jpg" /></td>
                          <td>&nbsp;</td>
                          <td>&nbsp;</td>
                          <td>&nbsp;<td>
                      </tr>
                  </table>
                  

                  这篇关于用 PHP 创建动态表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:每第三个循环后插入 tr 下一篇:使用 PHP 打印水平而不是垂直的表格

                  相关文章

                  最新文章

                  <i id='2BYzn'><tr id='2BYzn'><dt id='2BYzn'><q id='2BYzn'><span id='2BYzn'><b id='2BYzn'><form id='2BYzn'><ins id='2BYzn'></ins><ul id='2BYzn'></ul><sub id='2BYzn'></sub></form><legend id='2BYzn'></legend><bdo id='2BYzn'><pre id='2BYzn'><center id='2BYzn'></center></pre></bdo></b><th id='2BYzn'></th></span></q></dt></tr></i><div id='2BYzn'><tfoot id='2BYzn'></tfoot><dl id='2BYzn'><fieldset id='2BYzn'></fieldset></dl></div>
                  • <bdo id='2BYzn'></bdo><ul id='2BYzn'></ul>
                1. <tfoot id='2BYzn'></tfoot>
                      <legend id='2BYzn'><style id='2BYzn'><dir id='2BYzn'><q id='2BYzn'></q></dir></style></legend>

                      <small id='2BYzn'></small><noframes id='2BYzn'>