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 3 of 3
  1. #1
    Banned
    Join Date
    Jun 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    navigate pages generated from the select query

    Mentioned below is a PHP function , which can be used to navigate pages generated from the select query . ie. in the form of << Previous || Next >>

    <?


    function PagerNextPrevious(&$sql,$pagesize,$class='txt'){

    // Set Default Page Size to 20
    if($pagesize=="")
    $pagesize=20;
    $page=get_post('page');
    if($page!='NA'){
    $beg=($page-1)*$pagesize;
    $end=$pagesize;
    }else{
    $beg=0;
    $end=$pagesize;
    $page=1;
    }
    $rs=mysql_query($sql) ;
    $nrows=mysql_num_rows($rs);
    $sql=$sql." limit $beg,$end";
    $rs=mysql_query($sql);
    $subrows=mysql_num_rows($rs);

    if($nrows!=0){
    $from=(int)($beg)+1;
    $totalpages=(int)($nrows/$pagesize);
    $frac=($nrows/$pagesize);
    if(($frac-$totalpages)>0)
    $totalpages+=1;
    echo "( Page $page of $totalpages )&nbsp; &nbsp;&nbsp; ";
    if($page>1 ){
    echo "<a class=$class href='".selfq()."&page=".($page-1)."'> &lt;&lt;Previous </a>";
    }
    $next=$page+1;
    if($next <=$totalpages ){

    echo "&nbsp;&nbsp;&nbsp;<a class=$class href='".selfq()."&page=".$next."'> Next &gt;&gt; </a>";
    }

    }
    }

    // Assuming you have Opened connection to mysql database.

    $sql=" Select * from Products ";

    // Show the pager link in form of Previous||Next

    PagerNextPrevious($sql,20,'text');

    $rs=mysql_query($sql);
    if(mysql_num_rows($rs)>0){
    while($row=mysql_fetch_array($rs)){
    echo $row["ProductName"]."<br>";

    }
    }




    ?>

    Software Development India

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,036
    Thanks
    2
    Thanked 316 Times in 308 Posts
    The proper place to post a code snippet is - http://www.codingforums.com/post-php-snippet/

    When you post it in the PHP help forum, someone just thinks you need help with it but you forgot to post your question.

    Also, if you are going to be posting code that you expect someone else to be able to read and use -

    Wrap the code in PHP code tags so that it is readable/scrollable, use proper INDENTATION in your code, and use full <?php opening tags. More verbose comments that explain what each part of the code is and how it works would help make your code more readable and useful too.
    Last edited by CFMaBiSmAd; 07-02-2007 at 02:36 PM.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi.
    I have one question. I tried to use this code but I had problem could u help me ?there is selfq(). what is it, because when I wanna see the result there is an error for selfq()..
    best regards.


  •  

    Posting Permissions

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