简体   繁体   English

PHP MYSQL分页结果

[英]PHP MYSQL PAGING RESULTS

I wanted to create php paging with the base page is "Page 1" and the page links should start at "Page 2" leaving the "Page 1" link as an ordinary text not a link and when Im in "Second Page" the "Page 1" text becomes a link that leads to "First Page". 我想创建基本页面为“页面1”的php分页,页面链接应从“页面2”开始,而将“页面1”链接作为普通文本而不是链接,而当我在“第二页面”中时,页面1”文本成为指向“首页”的链接。

Like: When on the base page. 像:在基础页面上时。 /orders.php

<div id="page-links">
<b>1</b>, 
<a href="/orders.php?pagenum=2">2</a>, 
<a href="/orders.php?pagenum=3">3</a>
</div>

When on the 2nd page. 在第二页上时。 /orders.php?pagenum=2

<div id="page-links">
<a href="/orders.php?pagenum=1">1</a>, 
<b>2</b>, 
<a href="/orders.php?pagenum=3">3</a>
</div>

I have this php page: 我有这个php页面:

   <table>
      <?php
      $orders_check_raw = "select * from " . $orders . " where customers_id = '" . (int) $user_id . "'";
      $orders_check_query = mysql_query( $wpdb->prepare( $orders_check_raw ) );
      while ($orders_check = mysql_fetch_array( $orders_check_query )) {
        $blog_details = get_blog_details( $orders_check['blog_id'] );
        ?>

        <tr>
          <th class="check-column"><input type="checkbox" name="order[]" value=""></th>
          <td><?php echo str_pad( $orders_check['orders_id'], 7, '0', STR_PAD_LEFT ) . '<span style="display:none;">' . ltrim( str_pad( $orders_check['orders_id'], 7, '0', STR_PAD_LEFT ), '0' ) . '</span>'; ?></td>
          <td><?php echo $orders_check['payment_method']; ?></td>
          <td><?php echo date_short( $orders_check['date_purchased'] ); ?></td>
          <td><?php echo status_name( $orders_check['orders_status'] ); ?></td>
        </tr>
      <?php } ?>
    </tbody>
    </table>

Thank you. 谢谢。

I think you could use $_GET and an if...else statement to achieve your desired results. 我认为您可以使用$ _GET和if ... else语句来实现所需的结果。 For if..else http://www.w3schools.com/php/php_if_else.asp and for GET http://php.net/manual/en/reserved.variables.get.php . 对于if..else http://www.w3schools.com/php/php_if_else.asp和GET http://php.net/manual/zh/reserved.variables.get.php

if($_GET['pagenum']==1){
   echo '<div id="page-links"><b>1</b>, <a href="/orders.php?pagenum=2">2</a>, <a href="/orders.php?pagenum=3">3</a></div>';
}
else if (....) {
   ...
}
else (...) {
   ...
}

Ideally, you should define a constant to display entries per page. 理想情况下,您应该定义一个常量以每页显示条目。 Based on this, you should set an offset for you database query. 基于此,您应该为数据库查询设置偏移量。

For example: 例如:

define('ENTRIES_PER_PAGE', 15);

$orders_check_raw = "SELECT * FROM " . $orders . " WHERE customers_id = '" . (int) $user_id . "'";

$offset = $_GET['pagenum'] * ENTRIES_PER_PAGE;
$orders_check_raw .= "LIMIT " . ENTRIES_PER_PAGE . ", " . $offset;

$orders_check_query = mysql_query( $wpdb->prepare( $orders_check_raw ) );

Hope this helps. 希望这可以帮助。

You can write a php pagination yourself, that will take a little bit of effort. 您可以自己编写php分页,这需要一些工作。

OR 要么

Check this site . 检查此站点 It has a guide on how to create a pagination using PHP and MySQL ? 它具有如何使用PHP和MySQL创建分页的指南? you'll find it useful. 您会发现它很有用。

It is configurable and following are the few setting to give in short: 它是可配置的,以下是一些简短的设置:

  1. code to connect to your DB 连接到数据库的代码
  2. your table name. 您的表格名称。
  3. the number of adjacent pages to be shown on each side. 每侧要显示的相邻页面数。
  4. Number of items to show per page. 每页显示的项目数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM