SlideShare a Scribd company logo
SQL Limit in PHP

Introduction

PHP has an operator named LIMIT. Using the LIMIT operator you can fetch a minimum and
maximum row from a database. In this article you will see, how to execute the LIMIT
operator of MySQL in PHP.

Suppose that there are ten rows in a table of any database in MySQL. You want to fetch
only five rows from your database; then you will use the LIMIT operator.




Suppose there is the above table in your database. You want to fetch only five rows from
this table. For this purpose you will use the LIMIT operator. An example of the LIMIT
operator is as follows:

Example 1. If you want to see only five rows from a table in MySQL then you will use the
following query:

       select * from emp limit 5

Output




                      www.vineetsaini.wordpress.com
Example 2. If you want to see only five rows from a table in PHP form, then you will use
following code.

In this example, we have created a limit.php page, in which we execute a query with the
LIMIT operator. In the LIMIT operator we put minimum and maximum limit of the table
data. For example, the LIMIT 0,5 retrieves the row starting from row number 0 (the first
one) to a maximum of 5 rows.

Code

<html>
<title>Limit in PHP</title>
<body bgcolor="pink">
< h3><u>SQL Limit in PHP<u></h3>
<center>
<?php
 $con = mysql_connect("localhost","root","");
 if (!$con) {
 die( 'Could not connect: ' . mysql_error());
 }
 mysql_select_db ("sunderdeep", $con); // sunderdeep is a database name
 $result = mysql_query ("select * from emp limit 0,5"); // emp is the table name in
database
  echo " <table border='2' bgcolor ='skyblue'>
 <tr>
 <th align='center'>emp_id</th>
 <th align='center'>emp_Name</th>
 </tr>";
 while ($row = mysql_fetch_array ($result)) {
 echo "<tr>";
 echo "<td align='center'>" . $row ['emp_id'] . "</td>";
 echo "<td align='center'>" . $row ['emp_name'] . "</td>";
 echo "</tr>";
 }
echo "</table>";

  mysql_close ($con);
?>
</center>



                        www.vineetsaini.wordpress.com
</body>
</html>

The above file is saved with the name limit.php.

Output

When you browse your limit.php file then you will get the following output:




Conclusion

So in this article you saw, how to execute the LIMIT operator of MySQL in PHP. Using this
article one can easily understand how to execute the LIMIT operator of MySQL in PHP.




                      www.vineetsaini.wordpress.com

More Related Content

What's hot (15)

PDF
PHP and Mysql
Sankhadeep Roy
 
PPT
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
ODP
Database Connection With Mysql
Harit Kothari
 
PPT
Php MySql For Beginners
Priti Solanki
 
PPTX
Cake PHP 3 Presentaion
glslarmenta
 
PPT
Php, mysq lpart1
Subhasis Nayak
 
PPT
Drupalxamppxp 1229687989691791 1
beckman16
 
PPT
Database presentation
webhostingguy
 
PPT
Php Mysql
Mudasir Syed
 
PDF
PDO Basics - PHPMelb 2014
andrewdotcom
 
PDF
lab56_db
tutorialsruby
 
PPT
Lecture6 display data by okello erick
okelloerick
 
PPTX
Message enricher in mule
Sashidhar Rao GDS
 
PPTX
Php mysq
prasanna pabba
 
PHP and Mysql
Sankhadeep Roy
 
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
Database Connection With Mysql
Harit Kothari
 
Php MySql For Beginners
Priti Solanki
 
Cake PHP 3 Presentaion
glslarmenta
 
Php, mysq lpart1
Subhasis Nayak
 
Drupalxamppxp 1229687989691791 1
beckman16
 
Database presentation
webhostingguy
 
Php Mysql
Mudasir Syed
 
PDO Basics - PHPMelb 2014
andrewdotcom
 
lab56_db
tutorialsruby
 
Lecture6 display data by okello erick
okelloerick
 
Message enricher in mule
Sashidhar Rao GDS
 
Php mysq
prasanna pabba
 

Viewers also liked (11)

PDF
Browser information in PHP
Vineet Kumar Saini
 
PDF
CSS in HTML
Vineet Kumar Saini
 
PDF
Programming in C
Vineet Kumar Saini
 
PDF
Pagination in PHP
Vineet Kumar Saini
 
PDF
MVC in PHP
Vineet Kumar Saini
 
PDF
GET and POST in PHP
Vineet Kumar Saini
 
PDF
Practice exam php
Yesenia Sánchez Sosa
 
PDF
PHP Technical Questions
Pankaj Jha
 
PDF
Top 100 PHP Interview Questions and Answers
Vineet Kumar Saini
 
PDF
Top 100 .Net Interview Questions and Answer
Vineet Kumar Saini
 
PDF
Top C Language Interview Questions and Answer
Vineet Kumar Saini
 
Browser information in PHP
Vineet Kumar Saini
 
CSS in HTML
Vineet Kumar Saini
 
Programming in C
Vineet Kumar Saini
 
Pagination in PHP
Vineet Kumar Saini
 
MVC in PHP
Vineet Kumar Saini
 
GET and POST in PHP
Vineet Kumar Saini
 
Practice exam php
Yesenia Sánchez Sosa
 
PHP Technical Questions
Pankaj Jha
 
Top 100 PHP Interview Questions and Answers
Vineet Kumar Saini
 
Top 100 .Net Interview Questions and Answer
Vineet Kumar Saini
 
Top C Language Interview Questions and Answer
Vineet Kumar Saini
 
Ad

Similar to SQL Limit in PHP (20)

PPTX
Class 8 - Database Programming
Ahmed Swilam
 
PPTX
MySqL_n.pptx edshdshfbhjbdhcbjdchdchjcdbbjd
aidenreji
 
PDF
How MySQL can boost (or kill) your application v2
Federico Razzoli
 
PDF
Zurich2007 MySQL Query Optimization
Hiệp Lê Tuấn
 
PDF
Zurich2007 MySQL Query Optimization
Hiệp Lê Tuấn
 
PPT
SQL -PHP Tutorial
Information Technology
 
PDF
query optimization
Dimara Hakim
 
PDF
How MySQL can boost (or kill) your application
Federico Razzoli
 
PPTX
MySQL basics
Jamshid Hashimi
 
PDF
PHP with MySQL
wahidullah mudaser
 
PDF
Phorum MySQL tricks
guestd34230
 
PPSX
Workflow and Database Management
Veneet-BA
 
PPTX
Introduction to MySQL in PHP
hamsa nandhini
 
PPSX
Workflow Diagram
Shwetha-BA
 
PPSX
Workflow and Database Management
SwatiS-BA
 
PPT
Short Intro to PHP and MySQL
Jussi Pohjolainen
 
PDF
MySQL Performance Optimization
Mindfire Solutions
 
PDF
SQL Lesson 6 - Select.pdf
Madhusha15
 
PPSX
Workflow Diagram
Lakshmi-BA
 
Class 8 - Database Programming
Ahmed Swilam
 
MySqL_n.pptx edshdshfbhjbdhcbjdchdchjcdbbjd
aidenreji
 
How MySQL can boost (or kill) your application v2
Federico Razzoli
 
Zurich2007 MySQL Query Optimization
Hiệp Lê Tuấn
 
Zurich2007 MySQL Query Optimization
Hiệp Lê Tuấn
 
SQL -PHP Tutorial
Information Technology
 
query optimization
Dimara Hakim
 
How MySQL can boost (or kill) your application
Federico Razzoli
 
MySQL basics
Jamshid Hashimi
 
PHP with MySQL
wahidullah mudaser
 
Phorum MySQL tricks
guestd34230
 
Workflow and Database Management
Veneet-BA
 
Introduction to MySQL in PHP
hamsa nandhini
 
Workflow Diagram
Shwetha-BA
 
Workflow and Database Management
SwatiS-BA
 
Short Intro to PHP and MySQL
Jussi Pohjolainen
 
MySQL Performance Optimization
Mindfire Solutions
 
SQL Lesson 6 - Select.pdf
Madhusha15
 
Workflow Diagram
Lakshmi-BA
 
Ad

More from Vineet Kumar Saini (20)

PDF
Abstract Class and Interface in PHP
Vineet Kumar Saini
 
PDF
Add edit delete in Codeigniter in PHP
Vineet Kumar Saini
 
PDF
Introduction to Html
Vineet Kumar Saini
 
PDF
Computer Fundamentals
Vineet Kumar Saini
 
PDF
Country State City Dropdown in PHP
Vineet Kumar Saini
 
PDF
Stripe in php
Vineet Kumar Saini
 
PDF
Php Tutorials for Beginners
Vineet Kumar Saini
 
PDF
Install Drupal on Wamp Server
Vineet Kumar Saini
 
PDF
Joomla 2.5 Tutorial For Beginner PDF
Vineet Kumar Saini
 
PDF
Functions in PHP
Vineet Kumar Saini
 
PDF
Sorting arrays in PHP
Vineet Kumar Saini
 
PDF
Dropdown List in PHP
Vineet Kumar Saini
 
PDF
Update statement in PHP
Vineet Kumar Saini
 
PDF
Delete statement in PHP
Vineet Kumar Saini
 
PDF
Implode & Explode in PHP
Vineet Kumar Saini
 
PDF
Types of Error in PHP
Vineet Kumar Saini
 
PDF
Database connectivity in PHP
Vineet Kumar Saini
 
PDF
Arrays in PHP
Vineet Kumar Saini
 
PDF
Operators in PHP
Vineet Kumar Saini
 
PDF
Variables in PHP
Vineet Kumar Saini
 
Abstract Class and Interface in PHP
Vineet Kumar Saini
 
Add edit delete in Codeigniter in PHP
Vineet Kumar Saini
 
Introduction to Html
Vineet Kumar Saini
 
Computer Fundamentals
Vineet Kumar Saini
 
Country State City Dropdown in PHP
Vineet Kumar Saini
 
Stripe in php
Vineet Kumar Saini
 
Php Tutorials for Beginners
Vineet Kumar Saini
 
Install Drupal on Wamp Server
Vineet Kumar Saini
 
Joomla 2.5 Tutorial For Beginner PDF
Vineet Kumar Saini
 
Functions in PHP
Vineet Kumar Saini
 
Sorting arrays in PHP
Vineet Kumar Saini
 
Dropdown List in PHP
Vineet Kumar Saini
 
Update statement in PHP
Vineet Kumar Saini
 
Delete statement in PHP
Vineet Kumar Saini
 
Implode & Explode in PHP
Vineet Kumar Saini
 
Types of Error in PHP
Vineet Kumar Saini
 
Database connectivity in PHP
Vineet Kumar Saini
 
Arrays in PHP
Vineet Kumar Saini
 
Operators in PHP
Vineet Kumar Saini
 
Variables in PHP
Vineet Kumar Saini
 

Recently uploaded (20)

PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 

SQL Limit in PHP

  • 1. SQL Limit in PHP Introduction PHP has an operator named LIMIT. Using the LIMIT operator you can fetch a minimum and maximum row from a database. In this article you will see, how to execute the LIMIT operator of MySQL in PHP. Suppose that there are ten rows in a table of any database in MySQL. You want to fetch only five rows from your database; then you will use the LIMIT operator. Suppose there is the above table in your database. You want to fetch only five rows from this table. For this purpose you will use the LIMIT operator. An example of the LIMIT operator is as follows: Example 1. If you want to see only five rows from a table in MySQL then you will use the following query: select * from emp limit 5 Output www.vineetsaini.wordpress.com
  • 2. Example 2. If you want to see only five rows from a table in PHP form, then you will use following code. In this example, we have created a limit.php page, in which we execute a query with the LIMIT operator. In the LIMIT operator we put minimum and maximum limit of the table data. For example, the LIMIT 0,5 retrieves the row starting from row number 0 (the first one) to a maximum of 5 rows. Code <html> <title>Limit in PHP</title> <body bgcolor="pink"> < h3><u>SQL Limit in PHP<u></h3> <center> <?php $con = mysql_connect("localhost","root",""); if (!$con) { die( 'Could not connect: ' . mysql_error()); } mysql_select_db ("sunderdeep", $con); // sunderdeep is a database name $result = mysql_query ("select * from emp limit 0,5"); // emp is the table name in database echo " <table border='2' bgcolor ='skyblue'> <tr> <th align='center'>emp_id</th> <th align='center'>emp_Name</th> </tr>"; while ($row = mysql_fetch_array ($result)) { echo "<tr>"; echo "<td align='center'>" . $row ['emp_id'] . "</td>"; echo "<td align='center'>" . $row ['emp_name'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close ($con); ?> </center> www.vineetsaini.wordpress.com
  • 3. </body> </html> The above file is saved with the name limit.php. Output When you browse your limit.php file then you will get the following output: Conclusion So in this article you saw, how to execute the LIMIT operator of MySQL in PHP. Using this article one can easily understand how to execute the LIMIT operator of MySQL in PHP. www.vineetsaini.wordpress.com