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
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
פרייסז - השוואת מחירים בסופר
ZeroLag.com
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 : Pagination
Categories : PHP, Databases, MySQL Click here to Update Your Picture
leaping langoor
Date : Oct 28th 2005
Grade : 1 of 5 (graded 4 times)
Viewed : 25276
File : No file for this code example.
Images : No Images for this code example.
Search : More code by leaping langoor
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

A simple search with pagination in MySQL:

<?php
/***************************************************************
** Author : leapinglangoor [ [email protected] ]
** desc:
** This code will search trough records in an SQL database and
** display the amount of results that you want. If there are
** more records than the maximum amount it will display
** 'Previous 1,2,3,4,etc. 'Next'.
** Note : This code seems long and complicated but if you read
** the comment carefully you'll see its actually very easy!
** Also Edit the first line of the code to match your conditions
***************************************************************/

// PLease state your condition which will appear after WHERE in the sql
$cond = "`field` LIKE $foo";      // Or something

// Connect to SQL database
$global_db = mysql_connect('localhost', 'username', 'password');
mysql_select_db('databasename', $global_db);
// First query to find out how many reco
//     rds we have
$query = "SELECT Fields FROM Table WHERE $cond";



$result = mysql_query($query);
// Number of records found
$num_record = mysql_num_rows($result);
// Number of records you want to display
//     per page
$display = 25;
// Message when no records found
$XX = 'Sorry, no results were found!';
// If there are no records then startrow
//     is 0
if (empty($startrow)) {
   
$startrow=0;
}
// Actual query, watch the end of the qu
//     ery, here's where we set the LIMIT per p
//     age
$query2 = "SELECT Fields FROM Tabel WHERE your conditions LIMIT $startrow, $display";
$result2 = mysql_query($query2);
*
Put the results in a table
print("<table border=0><tr>");
*
I want only 3 results (in this case pictures) on 1 line, therefore i need a counter
$counter
= 0;
// Fetch the results (Begin loop)
while(list($Fields) = mysql_fetch_array($result2)) {
    * If
we have one line of three, move to the next line
   
if ($counter == 3) {
        print(
"</tr><tr>");
        *
Set the counter to zero
        $counter
= 0;
    }
   
// Display the results on the screen, th
    //     is is just an example, make your own tab
    //     el here
   
print("<td bgcolor=#004A80 width=200 height=200 align=center><font color=#FFFFFF>$Field1</font><br><a href=\"showdetail.php?ID=$id\"><img src=\"images/$Image\" border=0 width=170 height=170></a><br><font color=#FFFFFF>FL $PriceNlg   € $PriceEuro</font></td>");
    *
Increase the counter with 1
    $counter
= $counter + 1;
}
// End loop
// Calculate the previous results, only
//     print 'Previous' if startrow is not equa
//     l to zero
if ($startrow != 0) {
   
$prevrow = $startrow - $display;
    print(
"<a href=\"$PHP_SELF?startrow=$prevrow\">Previous</a> "); \\ Of cource here you can send more
} variables seperated by &
// Calculate the total number of pages
$pages = intval($num_record / $display);
// $pages now contains number of pages n
//     eeded unless there are left over from di
//     vision
if ($num_record % $display) {
   
// has left over from division, so add one page
   
$pages++;
}
// Print the next pages, first check if
//     there are more pages then 1
if ($pages > 1) {
    for (
$i=1; $i <= $pages; $i++) { // Begin loop
   
$nextrow = $display * ($i - 1);
    print(
"<a href=\"$PHP_SELF?startrow=$nextrow\">$i</a>  "); \\ Also here you can send more
   
} variables seperatd by &
}
//End loop
// Check if we are at the last page, if
//     so, dont print 'Next'
if (!(($startrow / $display) == $pages) && $pages != 1) {
   
// not the last page so print 'Next'
   
$nextrow = $startrow + $display;
    print(
"<a href=\"$PHP_SELF?startrow=$nextrow\">Next</a>");
}
// If there are no results at all
if ($num_record < 1) {
    print(
"<table border=0 width=795><tr><td>$XX</td></tr></table>");
}
?>



bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server.
Categories : Databases, MySQL, Complete Programs, 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 simple script to count and report hits and the last modification time of an HTML page. Requires MySQL support (other DBs should work too, except possibly mSQL).
Categories : HTTP, MySQL, PHP, Databases
Implementing a Members ONLY area
Categories : PHP, MySQL, Databases, Authentication
AJAX Data Grid System using php and mysql. A complete login system with the ability to display data in a grid using ajax. Add , update and delete the records without reloading the page.
Categories : PHP, AJAX, Databases, MySQL, Java Script
phpFormGenerator for Dynamic Form Generation from MySQL
Categories : PHP, PHP Classes, MySQL, Databases, HTML and PHP
Zip code range and distance calculation class v1.0.0
Categories : PHP, Databases, MySQL, Zip Code
Identify and log search engine access (spiders, robots, etc.) to a page.
Categories : HTTP, Environment Variables, PHP, MySQL, Databases
Cut your MySQL Connections to 1 line of code
Categories : PHP, Beginner Guides, Databases, MySQL
Simple function to return the number of days in a time span between 2 given dates.
Categories : PHP, Date Time, MySQL, Databases
Pull Down Surfing - Surf on Change
Categories : Java Script, MySQL, HTML and PHP, PHP, Databases
A Simple Script that stores encrypted messages in databases
Categories : PHP, Databases, MySQL, Security
[PHP5] aDB PDO LIKE Database Abstraction. Switch easily from one db server to another, strong errors management, manage transactions, queries preparation and more.
Categories : PHP, PHP Classes, Databases, MS SQL Server, MySQL
DBXML- A Class to backup databases in XML Format using web interface
Categories : PHP, PHP Classes, Databases, MySQL, XML