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
PHP Web Logs (BLogs)
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
Submit Site
Forex Trading Online forex trading platform

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 : Database resultset navigation
Categories : PHP, HTML and PHP, Databases, MySQL, Navigation Click here to Update Your Picture
Olaf Lederer
Date : Dec 03rd 2005
Grade : 3 of 5 (graded 2 times)
Viewed : 10456
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Olaf Lederer
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

Use this small function to create page links for your (MySQL) database resultset. This PHP function is all you need to create forward / backward links (paging) for the records in a database resultset. The setup is very easy, just call the function at the place where the links to have appear. Then create a variable for the current limit inside your SQL and create a variable with the total number of records in your resultset. The function takes care about an existing query string and creates the whole html code you need for the page navigation.

<?php
// example variable
$sql_limit = (isset($_GET['limit'])) ? $_GET['limit'] : 0;

function
navigation_links($curr_limit, $num_records, $limit_val, $limit_var = "limit", $next = "next >", $prev = "< prev", $seperator = "|") {
   
// rebuild query string
   
if (!empty($_SERVER['QUERY_STRING'])) {
       
$parts = explode("&", $_SERVER['QUERY_STRING']);
       
$newParts = array();
        foreach (
$parts as $val) {
            if (
stristr($val, $limit_var) == false) array_push($newParts, $val);
        }
       
$qs = (count($newParts) > 0) ? "&".implode("&", $newParts) : "";
    } else {
       
$qs = "";
    }
   
$navi = "";
    if (
$curr_limit > 0) {
       
$navi .= "<a href=\"".$_SERVER['PHP_SELF']."?".$limit_var. "=".($curr_limit-$limit_val).$qs."\">".$prev."</a>";
    }
   
$navi .= " ".$seperator." ";
    if (
$curr_limit < ($num_records-$limit_val)) {
       
$navi .= "<a href=\"".$_SERVER['PHP_SELF']."?".$limit_var. "=".($curr_limit+$limit_val).$qs."\">".$next."</a>";
    }
    return
trim($navi, " | ");
}

// example placing links ($num_all is the value of all records in you result set)
echo navigation_links($sql_limit, $num_all, 10);
?>



Record Set Paging with PHP (RSP)
Categories : PHP, MySQL, Navigation, Databases, HTML and PHP
Message of the Day - Random Message (Needs MySQL!)
Categories : Databases, HTML and PHP, PHP, MySQL
Alternating background color for HTML table rows
Categories : PHP, Databases, MySQL, HTML and PHP
A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL
Automatically printing the contents of an sql table in MySQL.
Categories : MySQL, PHP, HTML and PHP, Databases
Powerful php/mysql Pagination for up to 6 URL Params
Categories : PHP, PHP Classes, Databases, MySQL, Navigation
Pull Down Surfing - Surf on Change
Categories : Java Script, MySQL, HTML and PHP, PHP, Databases
Dynamically generated pop-ups (Select items)
Categories : PHP, HTML and PHP, MySQL, Databases
Creating thumbnails from MySQL Blobs online
Categories : PHP, MySQL, Graphics, HTML and PHP, Databases
Functions for loading images into a MySQL database and displaying them.
Categories : Graphics, HTML and PHP, MySQL, PHP, Databases
dynamic table columns
Categories : PHP, HTML and PHP, Arrays, Databases, MySQL
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
How can i Preload a 'SELECT MULTIPLE'?
Categories : HTML and PHP, PHP, MySQL, Databases
Paginating the mySQL data
Categories : PHP, Algorithms, Databases, MySQL, HTML and PHP