SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pagination problem

    hello, i am having problem with my pagination. i can pass the user input to the next page. any1 can help me? i dont know how to do it.


    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <?php

    include "dbconnect.php";
    $link=dbconnect();

    $pc = $_POST['pc'];


    $rowsPerPage = 4;



    $pageNum = 1;


    if(isset($_GET['page']))
    {
    $pageNum = $_GET['page'];
    }



    $offset = ($pageNum - 1) * $rowsPerPage;

    $query = "select *from doctors WHERE pc='$pc' ";

    $pagingQuery = "LIMIT $offset, $rowsPerPage";
    $result = mysql_query($query . $pagingQuery) or die('Error, query failed');


    $columns_counter=0;


    while($row = mysql_fetch_array( $result )) {


    echo "cus name:";
    echo $row['name'];

    }
    $columns_counter++;
    if($columns_counter==6){

    $columns_counter=0;
    }



    echo '<br><BR>';



    $result = mysql_query($query) or die('Error, query failed');
    $numrows = mysql_num_rows($result);


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

    $self = $_SERVER['PHP_SELF'];


    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 = ' [Prev] ';
    $first = ' [First Page] ';
    }


    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 = ' [Next] ';
    $last = ' [Last Page] ';
    }


    echo $first . $prev . " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " . $next . $last;


    ?>
    </body>
    </html>


    when i click onto the next button it cant retrieve any information. I think i m not able to pass user input. can any1 help me? i don know how to do it.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You are reading a variable "pc" from $_POST as well as the page number from $_GET.

    An HTTP request is either a POST or a GET, it can't be both. As you click the paging links, you're not submitting a form, $_POST['pc'] will never be set so you can't use that in the database query.

    You can pass it page to page by making it part of the paging links, and reading it from $_GET.


Bookmarks

Posting Permissions

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