0

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

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:

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

JvdBerg
  • 21,777
  • 8
  • 38
  • 55
Ken
  • 833
  • 2
  • 13
  • 27

3 Answers3

0

I think you could use $_GET and an if...else statement to achieve your desired results. 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($_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 (...) {
   ...
}
Jeremy
  • 587
  • 1
  • 7
  • 20
  • I can finish the code if you need more help and I sure there are different ways of achieving the result you want but this is the first thing that I thought of. Good luck! – Jeremy Sep 12 '12 at 07:53
  • [The official reference for if/else is here](http://php.net/manual/en/control-structures.elseif.php) – Jocelyn Sep 12 '12 at 07:55
0

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.

automaticAllDramatic
  • 2,025
  • 1
  • 21
  • 25
-1

You can write a php pagination yourself, that will take a little bit of effort.

OR

Check this site. It has a guide on how to create a pagination using PHP and 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.
mtk
  • 13,221
  • 16
  • 72
  • 112