dongsong4418 2015-04-22 22:21
浏览 18
已采纳

使用PHP从MySql数据库中提取内容并显示在3列中

I'm pulling content from MySQL database and I would like to display such content in 3 columns. I have managed to achieve it, but not all the content gets pulled. Even when I change it to 4 columns, it displays more content but still not all of them.

There must be a way to check how much content it is and display it correctly. Any help would be much appreciated.

This is what I have so far: (I'm supposed to display 52 items from database, but only 38 or so get displayed)

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>

<body>
    <div id="wrapper">
        <div id="page">
            <div id="content">
                <div id="report_content">
                    <div id="top_bar">
                            <h1 class="report_title"></h1>

                            <h2 class="report_subtitle"></h2>

                        <div id="criteria"></div>
                    </div>
                    <div>
                        <div>
                            <div id="t1" class="results resultList">
                                <?php if ($row_detail_vendors) { $temp_name='' ; ?>
                                <table>
                                    <?php $cols=4 ; do { ?>
                                    <tr>
                                        <?php for($i=1;$i<=$cols;$i++){ // All the rows will have $cols columns even if // the records are less than $cols $row_detail_vendors=m ysql_fetch_assoc($detail_vendors) ?>
                                        <td>    <a href="partner_info.php?idu=<?php echo $row_detail_vendors['shortcut']; ?>">
                            <?php echo ucfirst(strtoupper($row_detail_vendors['hotel_name'])); ?></a>

                                            <br>    <span><?php echo $row_detail_vendors['city']; ?>, <?php echo ucfirst($row_detail_vendors['country']); ?></span>

                                            <br/>
                                            <br/>
                                            </a>
                                        </td>
                                        <?php } ?>
                                    </tr>
                            </div>
                            <!--marketing-->
                            <?php } while ($row_detail_vendors=m ysql_fetch_assoc($detail_vendors)); ?>
                            <?php }?>
                        </div>
                    </div>
                </div>
                <!--marketing partners-->
            </div>
            <!--content-->
        </div>
        <!--page-->
</body>

  • 写回答

1条回答 默认 最新

  • dpr26232 2015-04-22 22:43
    关注

    Would advise:

    <div id="t1" class="results resultList">
      <table>
      <?php
        $cols=4;
        $i = 1;
        while($row_detail_vendors=mysql_fetch_assoc($detail_vendors)) {
            if($i % $cols == 1){
              echo "<tr>";  // start column wrapper
            } ?>
             <td><a href="partner_info.php?idu=<?php echo $row_detail_vendors['shortcut']);?>"><?php echo strtoupper($row_detail_vendors['hotel_name'])); ?></a>
              <br /><span><?php echo $row_detail_vendors['city']; ?>, <?php echo ucfirst($row_detail_vendors['country']); ?></span>
              <br/>
              <br/>
            </td>
          <?php
          if( $i % $cols == 0){
            echo "</tr>"; // End column wrapper
          }
          $i++;
        } ?>
      </table>
    </div>
    <!--marketing-->
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?