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 请问为什么我配置IPsec后PC1 ping不通 PC2,抓包出来数据包也并没有被加密
  • ¥200 求博主教我搞定neo4j简易问答系统,有偿
  • ¥15 nginx的使用与作用
  • ¥100 关于#VijeoCitect#的问题,如何解决?(标签-ar|关键词-数据类型)
  • ¥15 一个矿井排水监控系统的plc梯形图,求各程序段都是什么意思
  • ¥50 安卓10如何在没有root权限的情况下设置开机自动启动指定app?
  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了
  • ¥15 数学建模数学建模需要