Loading ...
Sorry, an error occurred while loading the content.

Need your help in my pagination

Expand Messages
  • metysoriano
    Hello experts: I have my pagination in PHP, when I search example science , it displays the desired output, its rows per page and offset, HOWEVER when I
    Message 1 of 1 , Jul 4 3:45 AM
    • 0 Attachment
      Hello experts:
      I have my pagination in PHP, when I search example 'science', it displays the desired output, its rows per page and offset, HOWEVER when I click the next page page or page 2, ALL data from A-Z will displays. It doest not follow the right row per page and offset, and it back to first record. below is my codes

      ****************************
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <title>Book Search</title>
      </head>

      <body link="#000000">
      <?php
      $book = $_POST['book'];
      $books = $_POST['books'];
      $link = $_POST['link'];
      $record_no = $_POST['record_no'];
      $whichone = $_POST['whichone'];

      include ('connector.php');


      //PAGINATION
      $rowsPerPage = 5;

      // by default we show first page
      $pageNum = (isset($_GET['page'])) ? (int) $_GET['page'] :1;

      // if $_GET['page'] defined, use it as page number

      // counting the offset
      $offset = ($pageNum - 1) * $rowsPerPage;



      $num = mysql_result(mysql_query("SELECT COUNT(record_no) as numrows FROM shcbooks WHERE book_title LIKE '$book%'"),0);


      $maxPage = ceil($num/$rowsPerPage);

      $self = $_SERVER['PHP_SELF'];
      $nav = '';


      $book_open_title = "SELECT * FROM shcbooks WHERE book_title LIKE '$book%' ORDER BY book_title ASC LIMIT $offset, $rowsPerPage";
      $booktitle = mysql_query($book_open_title) or die (mysql_error());



      ?>
      <table width="95%" border="1" cellspacing="0" cellpadding="0" align="center" bgcolor="#00FFFF">
      <tr>
      <td><font size="+1">Search Result/s for: <strong><u><?php echo $book; ?></u></strong></font></td>
      </tr>
      </table>

      <table width="95%" border="1" align="center" cellpadding="0" cellspacing="0">
      <!-- FIRST LINE -->
      <tr bgcolor="#DDDDDD">
      <!-- FIRST LINE -->


      <td width="45%" bgcolor="#FF0000"><font face="Arial Narrow" size="4"><div align="center"><strong>
      BOOK TITLE</strong></div></td>


      <td width="30%" bgcolor="#DDDDDD"><font face="Arial Narrow" size="4"><div align="center"><strong>
      BOOK AUTHOR</strong></div></td>



      <td width="15%" bgcolor="#DDDDDD"><font face="Arial Narrow" size="4"><div align="center"><strong>
      CALL #</strong></div></td>



      <td width="10%" bgcolor="#DDDDDD"><font face="Arial Narrow" size="4"><div align="center"><strong>
      LOCATION</strong></div></td>



      <td width="10%" bgcolor="#DDDDDD"><font face="Arial Narrow" size="4"><div align="center"><strong>
      STATUS</strong></div></td>

      <?php

      while ($row = mysql_fetch_array($booktitle))
      {
      ?>
      </tr>

      <tr bgcolor="#EEEEEE">


      <td><div align="left"><font face="Arial Narrow" size="3"><strong>
      <img src="book.jpg" align="middle">
      <?php echo "<a href ='book_open.php?books=".$row['record_no']."'>".
      $row['book_title']; ?></a></strong></font></div></td>


      <td><div align="left"><font face="Arial Narrow" size="3"><strong>
      <img src="author.jpg" align="middle">
      <?php echo $row['book_author']; ?></strong></font></div></td>

      <td><div align="center"><font face="Arial Narrow" size="3"><strong>
      <?php echo $row['callno']; ?></strong></font></div></td>

      <td><div align="center"><font face="Arial Narrow" size="3"><strong>
      <?php echo $row['location']; ?></strong></font></div></td>


      <td><div align="center"><font face="Arial Narrow" size="3"><strong>
      <?php echo $row['status']; ?></strong></font></div></td>

      <?php



      }


      ?>


      </tr>
      </table>
      <?php



      for($page = 1; $page <= $maxPage; $page++)
      {
      if ($page == $pageNum)
      {
      $nav.= " $page "; // no need to create a link to current page
      }
      else
      {
      $nav.= " <a href=\"$self?page=$page\">$page</a> ";
      }
      }

      if ($pageNum > 1)
      {
      $page = $pageNum - 1;
      $prev = " <a href=\"$self?page=$page\">[Prev]</a> ";

      $first = " <a href=\"$self?page=1\">[First Page]</a> ";
      }
      else
      {
      $prev = ' '; // we're on page one, don't print previous link
      $first = ' '; // nor the first page link
      }

      if ($pageNum < $maxPage)
      {
      $page = $pageNum + 1;
      $next = " <a href=\"$self?page=$page\">[Next]</a> ";

      $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
      }
      else
      {
      $next = ' '; // we're on the last page, don't print next link
      $last = ' '; // nor the last page link
      }




      // print the navigation link

      echo $first . $prev . $nav . $next . $last;
      mysql_query($numrows);
      mysql_close($book_connect);

      ?>
      </body>
      </html>

      *********************

      I need your help experts..

      Thanks a LOT. I am new to PHP.
    Your message has been successfully submitted and would be delivered to recipients shortly.