473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

paging

chelvan
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
3 1105
maheswaran
190 100+
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
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
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

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

Similar topics

0
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update...
2
by: RelaxoRy | last post by:
sqlConnection1.Open(); myReader = sqlCommand1.ExecuteReader(); DataGrid1.DataSource = myReader; DataGrid1.DataBind(); myReader.Close(); sqlConnection1.Close(); The Datagrid populates fine. ...
1
by: Guoqi Zheng | last post by:
Sir, The default paging of datagrid is somehow use too much resource, so I am using Stored procedure for the paging. You can find my Stored procedure at the end of this message. It works...
6
by: Shawn | last post by:
Hi. I already have a datagrid where I'm using paging. I have a stored procedure that fills a temp table with 200-500 rows and then sends back 10 records at the time. When I go to page 2 the SP...
2
by: asad | last post by:
Hello friends, i am designing a ASP.NET page where i want to use custom paging bcoz data is too heavy so pls tell me how can i use custom paging in ASP.NET Thanks
2
by: farhad13841384 | last post by:
Hi , I Hope You fine. I have some problem with this code for paging in asp.net this bottom code work correctly without any error but when I try to place separate code in .VB file then error is...
0
by: anonieko | last post by:
This approach I found very efficient and FAST when compared to the rowcount, or Subquery Approaches. This is before the advent of a ranking function from DB such as ROW_NUMBER() in SQL Server...
2
by: rn5a | last post by:
In a shopping cart app, a ASPX page retrieves the order details & personal details of a user from a MS-Access database table depending upon the username of the user. The order details of a...
3
by: Ronald S. Cook | last post by:
I was told that if calling lots of records from the database (let's say 100,000), that the GridView's paging feature would automatically "handle" everything. But the 100,000 records are still...
5
by: Donald Adams | last post by:
Hi, I will have both web and win clients and would like to page my data. I could not find out how the datagrid control does it's paging though I did find some sample code that says they do it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.