By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,824 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

paging

chelvan
P: 90
hi
all
its me again

on my displaying page, i want to limit the records to display on it. and display the link to go next pages to view the balance.

is it possible?

thanks in advance.




chel--1
Sep 19 '08 #1
Share this Question
Share on Google+
3 Replies


100+
P: 190
ya its possible, try limit in ur query according to ur page index.


see this

http://www.plus2net.com/php_tutorial/php_paging.php
Sep 19 '08 #2

chelvan
P: 90
hi all
thanks.......

i got it.....



Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $rowsPerPage = 3;
  4.  
  5. $pageNum = 1;
  6. if(isset($_GET['page']))
  7. {
  8.     $pageNum = $_GET['page'];
  9. }
  10.  
  11.  
  12. $offset = ($pageNum - 1) * $rowsPerPage;
  13.  
  14. $query = " SELECT * FROM user " .
  15.          " LIMIT $offset, $rowsPerPage";
  16. $result = mysql_query($query) or die('Error, query failed');
  17.  
  18. while($row = mysql_fetch_array($result))
  19. {
  20.  // reading database
  21. }
  22.  
  23. echo "<table align='center' border='0'>";
  24. //printing
  25. echo "</table>";
  26.  
  27.  
  28. $query   = "SELECT COUNT(refno) AS numrows FROM myfriends WHERE refno='$refno'";
  29. $result  = mysql_query($query) or die('Error, query failed');
  30. $row     = mysql_fetch_array($result, MYSQL_ASSOC);
  31. $numrows = $row['numrows'];
  32.  
  33. $maxPage = ceil($numrows/$rowsPerPage);
  34.  
  35.  
  36. $self = $_SERVER['PHP_SELF'];
  37. $nav  = '';
  38.  
  39. for($page = 1; $page <= $maxPage; $page++)
  40. {
  41.    if ($page == $pageNum)
  42.    {
  43.       $nav .= " $page "; // no need to create a link to current page
  44.    }
  45.    else
  46.    {
  47.       $nav .= " <a href=\"$self?page=$page\">$page</a> ";
  48.    } 
  49. }
  50.  
  51. if ($pageNum > 1)
  52. {
  53.    $page  = $pageNum - 1;
  54.    $prev  = " <a href=\"$self?page=$page\">[Prev]</a> ";
  55.  
  56.    $first = " <a href=\"$self?page=1\">[First Page]</a> ";
  57. else
  58. {
  59.    $prev  = '&nbsp;'; 
  60.    $first = '&nbsp;'; 
  61. }
  62.  
  63. if ($pageNum < $maxPage)
  64. {
  65.    $page = $pageNum + 1;
  66.    $next = " <a href=\"$self?page=$page\">[Next]</a> ";
  67.  
  68.    $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
  69. else
  70. {
  71.    $next = '&nbsp;'; 
  72.    $last = '&nbsp;'; 
  73. }
  74.  
  75. echo "<br><br>";
  76. echo $first . $prev . $nav . $next . $last;
  77.  
  78. ?>
  79.  
  80.  


chel-1
Sep 19 '08 #3

chelvan
P: 90
ya its possible, try limit in ur query according to ur page index.


see this

http://www.plus2net.com/php_tutorial/php_paging.php
thanks maheswaran

chel-1
Sep 19 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.