Location: PHPKode > scripts > pn_buttons > pn_buttons/pn.class.php
<?
##################################
# Author : Dimitris Kossikidis
# E-mail : hide@address.com
##################################

class pn_buttons{

      /* Public Variables */
      var $query_total_pages = 0;
      var $limited_query;
      var $next_button;
      var $previous_button;

      /* Functions */
      function pn_buttons($sql, $step, $page=0){
          $result = mysql_query( $sql );
          $query_total_rows = mysql_num_rows( $result );

          // if query return some rows
         if ( $query_total_rows>0 ){

             if ( $query_total_rows%$step!=0 ){
                $total_pages = intval( $query_total_rows/$step)+1;
             }else{
                $total_pages = $query_total_rows/$step ;
             }

             $this->query_total_pages = $total_pages;
             
             // if page is set
             if ( empty($page) ) {
                $from = 0;
                $this->current_page= 1;
             }else{
                if ( $page <= $this->query_total_pages ) {
                     $from = $step * ( $page - 1 );
                     $this->current_page= $page;
                }else{
                     $from = 0;
                     $this->current_page= 1;
                }
             }
             
             $this->limited_query = $sql . " LIMIT ". $from .", ". $step;
          }

      } // end  function

      // create previous and next buttons
      function make_buttons( $link, $link_params, $txt_next="next", $txt_previous="previous", $image="" ){

          if ( $this->query_total_pages>1 ){

              if ( ($this->current_page < $this->query_total_pages) && ($this->current_page>1) ){
                  $next_page = $this->current_page+1;
                  $prev_page = $this->current_page-1;
                  $next_lnk = "<a href='".$link . $link_params . "&page=". $next_page ."'>$txt_next</a>";
                  $prev_lnk = "<a href='".$link . $link_params . "&page=". $prev_page ."'>$txt_previous</a>";
              }else if( ($this->current_page < $this->query_total_pages) && ($this->current_page==1) ){
                  $next_page = $this->current_page+1;
                  $prev_page = "";
                  $next_lnk = "<a href='".$link . $link_params . "&page=". $next_page ."'>$txt_next</a>";
                  $prev_lnk = "";
              }else if( $this->current_page >= $this->query_total_pages ){
                  $next_page = "";
                  $prev_page = $this->current_page-1;
                  $next_lnk = "";
                  $prev_lnk = "<a href='".$link . $link_params . "&page=". $prev_page ."'>$txt_previous</a>";
              }
              $this->next_button = $next_lnk;
              $this->previous_button = $prev_lnk;
          }

      } // end function

      // display all pages
      function count_all_pages( $link, $link_params ){
          for ($i=1; $i<=$this->query_total_pages; $i++){
              if ($i==$this->current_page){
                  echo "<b>[$i]</b>";
              }else{
                  echo "<a href='$link$link_params&page=$i'>[$i]</a>";
              }
          }
      }

} // end Class

?>
Return current item: pn_buttons