WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Complex paging with no resultset limit
Categories : PHP, MySQL, Databases, Output Control, HTML and PHP Click here to Update Your Picture
bastien koert
Date : Mar 05th 2005
Grade : 4 of 5 (graded 7 times)
Viewed : 7932
File : No file for this code example.
Images : No Images for this code example.
Search : More code by bastien koert
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

This shows how to page thru a large resultset in a simple manner. It produces a set of links where-ever its called that looks like:

[ << 1 2 3 4 >> ]

and so on.

Bastien


<?php
/*
  show_pages shows the links to the different pages
  it gets passed the current offset and the total number of images to
  show on one page ($display_length)
*/
function show_pages($offset, $display_length)
{
       
//run a query to see how many records there are total.
     
$total        = '';     //resource handle for the query
     
$total_images = 0;      //total number of elements in the paging system
     
$pages        = 0;      //number of pages calculated in the script
     
$base_offset  = 0;      //starting point for offsets
     
$show_pages   = 3;      //number of links to show as pages
     
$start_page   = 1;      //index number of the page to start with
     
     
     
echo "<table width='100%'><tr><td align='center'><b>[ ";
     
$sql = "select count(*) from photos";
     
$total  = query($sql);
      if (
mysql_num_rows($total)==1)
      {
       
$row = mysql_fetch_array($total);
       
$total_images = $row[0];
       
$pages = floor($total_images/$display_length);  //calc the number of links to show (ceil rounds up to next int)

       
if ($pages > $show_pages)
        {
         
$base_offset = $offset - $display_length;
         
//can't go past first page
         
if ($base_offset < 0){ $base_offset = 0; }
         
$start_page  = $base_offset / $display_length;
         
$end_page    = $show_pages + $start_page;
         
//can't go past last page
         
if ($end_page > $pages) { $end_page = $pages; }
        }
//end if
       
if ($start_page > 1)
        {
           echo
"<a href=\"".$_SERVER['PHP_SELF']."?offset=".($base_offset-$display_length)."\"><<</a>  ";
        }
        for (
$x = $start_page ; $x <= $end_page; $x++)
        {

         
//don't show current page as link
         
if ($base_offset == $offset)
          {
            echo
"$x ";
          }else{

            echo
"<a href=\"".$_SERVER['PHP_SELF']."?offset=$base_offset\">$x</a>  ";
          }
//end if
         
$base_offset += $display_length;
        }
//next
       
if ($pages > $end_page)
        {
           echo
"<a href=\"".$_SERVER['PHP_SELF']."?offset=$base_offset\">>></a>  ";
        }


      }else{

         echo
"No other images found";

      }

      echo
"]</b></td></tr></table>";
}
//end function
?>



phpFormGenerator for Dynamic Form Generation from MySQL
Categories : PHP, PHP Classes, MySQL, Databases, HTML and PHP
Functions for loading images into a MySQL database and displaying them.
Categories : Graphics, HTML and PHP, MySQL, PHP, Databases
Dynamically generated pop-ups (Select items)
Categories : PHP, HTML and PHP, MySQL, Databases
Message of the Day - Random Message (Needs MySQL!)
Categories : Databases, HTML and PHP, PHP, MySQL
Required form fields that pull from MySQL database
Categories : PHP, HTML and PHP, Databases, MySQL
mySQL/PHP/search with multientry form and table output with colored rows
Categories : PHP, Beginner Guides, MySQL, HTML and PHP, Databases
Creating thumbnails from MySQL Blobs online
Categories : PHP, MySQL, Graphics, HTML and PHP, Databases
Function to do live population of HTML's <Select> tag from a Table
Categories : PHP, MySQL, HTML and PHP, Databases
Storing / Retrieving pictures from database This can be used for banner / ads exchange. very useful for people developing big portal with ads in the site........
Categories : PHP, MySQL, Databases, HTML and PHP
Record Set Paging with PHP (RSP)
Categories : PHP, MySQL, Navigation, Databases, HTML and PHP
Alternating background color for HTML table rows
Categories : PHP, Databases, MySQL, HTML and PHP
Editing the virtusertable and sendmail.cw via PHP3.0 and Mysql
Categories : MySQL, HTML and PHP, PHP, Databases
This function will populate the options in a drop down HTML select list in a form from a database query.
Categories : MySQL, General SQL, PHP, HTML and PHP, Databases
html split bar used to split in multiple pages a database result
Categories : HTML and PHP, Databases, MySQL, PHP
Database resultset navigation
Categories : PHP, HTML and PHP, Databases, MySQL, Navigation