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
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



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 : SQL_CALC_FOUND_ROWS - How to know the number of rows a query would have returned if there was no LIMIT set on the query using php5 and mysqli.Usfull with Pagination (Paging).
Categories : PHP, Databases, MySQL Click here to Update Your Picture
Igal Rubinstein
Date : Jun 08th 2007
Grade : 3 of 5 (graded 3 times)
Viewed : 21755
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Igal Rubinstein
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

Many times we use the LIMIT option in MySQL to limit the number of records returned for a given
query. A feature most web developers commonly use is pagination. When showing the little numbers
pointing back and forth to previous and next pages, we need to both know how many records are in
total and at the same time we need to show only one page of results.

Many developers simply run the query twice. Once without the LIMIT to see how many records answer
the query and a second time to actually get the limited data needed to show.

Another approach to this is to use SQL_CALC_FOUND_ROWS. This methos is faster than running the same
query twice. Lets look at a simple query :

<?php
//Use $Result to show the data
$Result=mysqli_query($link,"SELECT SQL_CALC_FOUND_ROWS  FirstName,LastName From UserBase LIMIT 10");

// The number of rows that actually returned for the query (Can be less than the limit)
$NumberOfResults=mysqli_num_rows($Result);

$NORResult=mysqli_query($link,"Select FOUND_ROWS()");
$NORRow=mysqli_fetch_array($NORResult);

//This is the number of results that would have been returned if the query did not have LIMIT 10 at
//the end. You can now use this number to calculate the number of pages in your pagination.
$NOR=$NORRow["FOUND_ROWS()"];
?>


This code example will also work on PHP4, just use mysql_ instead of mysqli_.

From the MySQL Manual :
In the absence of the SQL_CALC_FOUND_ROWS option in the most recent SELECT statement, FOUND_ROWS()
returns the number of rows in the result set returned by that statement.
The row count available through FOUND_ROWS() is transient and not intended to be available past the
statement following the SELECT SQL_CALC_FOUND_ROWS statement. If you need to refer to the value later, save it.

More info at : http://dev.mysql.com/doc/refman/4.1/en/information-functions.html








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
Automatically printing the contents of an sql table in MySQL.
Categories : MySQL, PHP, HTML and PHP, Databases
Finds the median in an array of numbers - Can be used with a MySql database column read into an array
Categories : PHP, Arrays, Databases, MySQL
free, search engine, indexing, system, information, web, ftp, http, free, software, cgi, php, MySQL, database, php3, FreeBSD, Linux, Unix, UdmSearch
Categories : MySQL, Complete Programs, PHP, Databases, Search
Required form fields that pull from MySQL database
Categories : PHP, HTML and PHP, Databases, MySQL
Simple Mini Poll class library (SimPoll)
Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs
I`d like to use the mysql_fetch_row function along with a "randomizer" function that would give me a random result from a mySQL table.
Categories : General SQL, MySQL, PHP, Databases
PHP and MySQL scripting for Muyltiple CheckBoxes
Categories : HTML and PHP, MySQL, Databases, PHP
Inserting data to a MySQL Database using AJAX
Categories : AJAX, HTTP, PHP, Databases, MySQL
How can i Preload a 'SELECT MULTIPLE'?
Categories : HTML and PHP, PHP, MySQL, Databases
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
This functions makes it easy to use session-variables known from ASP. With one Cookie the array "session" will save and restore from a db-record. In this version MySQL is used but it's should very easy to change
Categories : PHP, Arrays, Cookies, MySQL, Databases
mediaCat-GTK v2.0.0 - an mp3/cd/dvd cataloging utility written in php-gtk which interfaces with mysql and ms access (or db supported by PHP's Unified ODBC Functions)
Categories : PHP, MySQL, MS Access, Utilities, Databases
Simple function to return the number of days in a time span between 2 given dates.
Categories : PHP, Date Time, MySQL, Databases