WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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
bastien koert
Date : Mar 05th 2005
Grade : 4 of 5 (graded 7 times)
Viewed : 10290
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  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
?>



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
Message of the Day - Random Message (Needs MySQL!)
Categories : Databases, HTML and PHP, PHP, MySQL
This program will take data from a user via a web based form, validate it, show it to the user for re-validation, and finally insert it into the database. Plenty of sanity checking on the fields in the form.
Categories : MySQL, HTML and PHP, PHP, Complete Programs, Databases
Automatically printing the contents of an sql table in MySQL.
Categories : MySQL, PHP, HTML and PHP, Databases
Required form fields that pull from MySQL database
Categories : PHP, HTML and PHP, Databases, MySQL
How can i Preload a 'SELECT MULTIPLE'?
Categories : HTML and PHP, PHP, MySQL, Databases
bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
mySQL/PHP/search with multientry form and table output with colored rows
Categories : PHP, Beginner Guides, MySQL, HTML and PHP, Databases
Record Set Paging with PHP (RSP)
Categories : PHP, MySQL, Navigation, Databases, HTML and PHP
Database resultset navigation
Categories : PHP, HTML and PHP, Databases, MySQL, Navigation
Creating thumbnails from MySQL Blobs online
Categories : PHP, MySQL, Graphics, 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
A script to generate a report from a valid mysql connection. The user has to supply which fields he wants to display in table. All properties are changable.
Categories : PHP, PHP Classes, Databases, MySQL, HTML and PHP
Alternating background color for HTML table rows
Categories : PHP, Databases, MySQL, HTML and PHP