Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Oct 2009
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    need help in pagination

    hi i create a pagination and its code is down below
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled Document</title>
    </head>
    
    <body>
    <?php
    mysql_connect("localhost");
    mysql_select_db("test");
    
    $per_page = 5;
    $start = $_GET['start'];
    
    $record_count = mysql_num_rows(mysql_query("select * from data"));
    
    $max_pages = $record_count/$per_page;
    
    if(!$start)
       $start = 0;
    
    $get = mysql_query("select * from data limit $start, $per_page");
    while($row=mysql_fetch_assoc($get))
    {
       $name = $row['name'];
       $age = $row['age'];
       
       echo $name." (".$age.")<br>";
    }
    $prev = $start - $per_page;
    $next = $start + $per_page;
    
    if(!($start<=0))
       echo "<a href='pagination.php?start=$prev'>Prev</a> ";
       
    $i=1;
    
    for($x=0;$x<$record_count;$x=$x+$per_page)
    {
       if($start!=$x)
          echo " <a href='pagination.php?start=$x'>$i</a> ";
       else
          echo " <a href='pagination.php?start=$x'><b>$i</b></a> ";
       $i++;
    }
       
    if(!($start>=$record_count-$per_page))
       echo " <a href='pagination.php?start=$next'>Next</a>";
    ?>
    </body>
    </html>
    problem in this code is when i load this page first time then it displays this error
    Code:
    Notice: Undefined index: start in D:\wamp\www\examples\pagination.php on line 14
    but when i click next or prev buttons then it works fine.
    how this can be solved?

  • #2
    Regular Coder seco's Avatar
    Join Date
    Nov 2008
    Location
    Oregon
    Posts
    687
    Thanks
    6
    Thanked 79 Times in 77 Posts
    try using POST rather than GET

    from
    PHP Code:
    $start $_GET['start']; 
    to
    PHP Code:
    $start $_POST['start']; 

  • #3
    New Coder
    Join Date
    Oct 2009
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    still not working
    still the same error

  • #4
    Regular Coder FWDrew's Avatar
    Join Date
    Apr 2008
    Location
    Missouri
    Posts
    380
    Thanks
    38
    Thanked 45 Times in 43 Posts
    Quote Originally Posted by seco View Post
    try using POST rather than GET

    from
    PHP Code:
    $start $_GET['start']; 
    to
    PHP Code:
    $start $_POST['start']; 
    Why would you do this when paginating? You can forget bookmarking any URL if you do it with a post request for every page. A GET request is absolutely what is needed.

    Try changing this:
    PHP Code:
    $start $_GET['start']; 
    To this:
    PHP Code:
    $start = (isset($_GET['start']) ? $_GET['start'] : 0); 
    Dev-Tips.com || Employee at the Envato Network || My Portfolio

  • #5
    New to the CF scene
    Join Date
    Aug 2009
    Location
    Ottawa, ON
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    have you tried to check the code in your index code???

    is there any page you were using??? maybe the error was in that page that's why it shows this notice of error

  • #6
    New Coder
    Join Date
    Oct 2009
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks to all of you.

    its working now. especially thanks to FWDrew your reply was the correct


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •