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

使用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>

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-->