【问题标题】:Table in PHP from DB only showing 61 entries?数据库中的 PHP 表仅显示 61 个条目?
【发布时间】:2017-08-09 05:14:24
【问题描述】:

试图显示一个包含 150 多个条目但仅显示 61 个条目的表格,我如何让所有条目无限期地显示在页面上或添加“页面”功能以便我们可以浏览所有条目,而不仅仅是最多 61 个条目?

<div id="page-wrapper">
<div class="row">
    <div class="col-lg-12">
        <h1 class="page-header">Posting Info</h1>
    </div>
</div>
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                Post Info Table
            </div>
            <div class="panel-body">
                <div class="row-sm-4">
                    <div class="col-lg-6" style="width: 100% !important;">
                        <form role="form" style="width: 100% !important;">
                              <div class="table-responsive" style="width: 100% !important;">
                                 <table class="table table-bordered table-striped" style="width: 100% !important;">
                                     <thead>
                                         <tr>
                                             <th>Example1</th>
                                             <th>Example2</th>
                                             <th>Example3</th>
                                             <th>Example4</th>
                                             <th>Example5</th>
                                             <th>Example6</th>
                                             <th>Example7</th>
                                             <th>Example8</th>
                                         </tr>
                                     </thead>
                                     <tbody>
                                           <?php
                                                $postList = '';
                                                $q = $db->prepare("SELECT * FROM `examples`");
                                                $q->execute();
                                                $q = $q->fetchAll();

                                                foreach ($q as $post)
                                                {
                                                      $postList .= '<tr> <td>'.$post['exmpl1'].'</td>
                                                                                  <td>'.$post['exmpl2'].'</td>
                                                                                  <td>'.$post['exmpl3'].'</td>
                                                                                  <td><a href="../'.$post['exmpl4'].'">Click to View</a></td>
                                                                                  <td>'.$post['exmpl5'].'</td>
                                                                                  <td>'.$post['exmpl6'].'</td>
                                                                                  <td>'.$post['exmpl7'].'</td>
                                                                                  <td>'.$post['exmpl8'].'</td>
                                                      </tr>';
                                                }

                                                print $postList;
                                          ?>
                                     </tbody>
                                 </table>
                             </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

目前最多只能显示 61 个条目,但条目中的所有信息都可以正确显示。该代码有效,但似乎受到限制。我正在寻找消除此限制的方法。

【问题讨论】:

  • 向示例表中添加更多记录 :)
  • 数据库中有 137 条记录,但只有 61 条被放入该表中。这就是问题:(
  • 找到数组 $q 的长度,所以你应该找到查询返回的确切值

标签: php sql database html-table


【解决方案1】:

您的代码看起来不错,它应该显示所有匹配的行。

您应该使用echo 'There are ' . $q-&gt;rowCount() . ' rows found.'; 对其进行调试,这将输出找到的行数。

至于页面功能,它被称为pagination,你应该看看如何制作。

【讨论】:

  • 可能听起来很愚蠢,但我会将您的回声测试字符串放在哪里?我已经把它放在了几个地方,它什么也没做:/
  • 就在 之后插入以下 = echo 'There are ' 。 $q->rowCount() 。 '找到的行。'; ?>
  • 把它放在那个位置,它没有做任何事情另外,不得不将它改为“打印”而不是“回声”
  • 您没有收到任何错误吗?这里不需要打印/回显。尝试将其更改为 &lt;?= '&lt;script&gt;alert("' . $q-&gt;rowCount() . ' rows");&lt;/script&gt;'; ?&gt; 您应该会收到 JavaScript 警报。
  • 它说“说 1 行”但正在显示 61 行
【解决方案2】:

在您的选择查询中添加LIMIT 200

【讨论】:

  • 添加它,现在它在表格中显示 35 个条目。很困惑?
【解决方案3】:

$q=mysql_query("select * from students limit 61");

$num_row = mysql_num_row($q);

你可以这样使用

【讨论】:

  • 我不希望它只显示 61,它只显示 61,仅此而已。我试图让它显示所有条目
猜你喜欢
  • 2014-05-21
  • 1970-01-01
  • 2020-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-20
相关资源
最近更新 更多