SlideShare une entreprise Scribd logo
1  sur  3
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances (15)

PHP and Mysql
PHP and MysqlPHP and Mysql
PHP and Mysql
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
Database Connection With Mysql
Database Connection With MysqlDatabase Connection With Mysql
Database Connection With Mysql
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
 
Cake PHP 3 Presentaion
Cake PHP 3 PresentaionCake PHP 3 Presentaion
Cake PHP 3 Presentaion
 
Php, mysq lpart1
Php, mysq lpart1Php, mysq lpart1
Php, mysq lpart1
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Drupalxamppxp 1229687989691791 1
Drupalxamppxp 1229687989691791 1Drupalxamppxp 1229687989691791 1
Drupalxamppxp 1229687989691791 1
 
Database presentation
Database presentationDatabase presentation
Database presentation
 
Php Mysql
Php Mysql Php Mysql
Php Mysql
 
PDO Basics - PHPMelb 2014
PDO Basics - PHPMelb 2014PDO Basics - PHPMelb 2014
PDO Basics - PHPMelb 2014
 
lab56_db
lab56_dblab56_db
lab56_db
 
Lecture6 display data by okello erick
Lecture6 display data by okello erickLecture6 display data by okello erick
Lecture6 display data by okello erick
 
Message enricher in mule
Message enricher in muleMessage enricher in mule
Message enricher in mule
 
Php mysq
Php mysqPhp mysq
Php mysq
 

En vedette (11)

Browser information in PHP
Browser information in PHPBrowser information in PHP
Browser information in PHP
 
CSS in HTML
CSS in HTMLCSS in HTML
CSS in HTML
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Pagination in PHP
Pagination in PHPPagination in PHP
Pagination in PHP
 
MVC in PHP
MVC in PHPMVC in PHP
MVC in PHP
 
GET and POST in PHP
GET and POST in PHPGET and POST in PHP
GET and POST in PHP
 
Practice exam php
Practice exam phpPractice exam php
Practice exam php
 
PHP Technical Questions
PHP Technical QuestionsPHP Technical Questions
PHP Technical Questions
 
Top 100 PHP Interview Questions and Answers
Top 100 PHP Interview Questions and AnswersTop 100 PHP Interview Questions and Answers
Top 100 PHP Interview Questions and Answers
 
Top 100 .Net Interview Questions and Answer
Top 100 .Net Interview Questions and AnswerTop 100 .Net Interview Questions and Answer
Top 100 .Net Interview Questions and Answer
 
Top C Language Interview Questions and Answer
Top C Language Interview Questions and AnswerTop C Language Interview Questions and Answer
Top C Language Interview Questions and Answer
 

Similaire à SQL Limit in PHP

Similaire à SQL Limit in PHP (20)

My sql.ppt
My sql.pptMy sql.ppt
My sql.ppt
 
Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database Programming
 
MYSQL
MYSQLMYSQL
MYSQL
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
 
Php verses MySQL
Php verses MySQLPhp verses MySQL
Php verses MySQL
 
Mysql
MysqlMysql
Mysql
 
My sql
My sqlMy sql
My sql
 
Web-based application development part 31MINIMIZE .docx
Web-based application development part 31MINIMIZE .docxWeb-based application development part 31MINIMIZE .docx
Web-based application development part 31MINIMIZE .docx
 
Oracle sql tuning
Oracle sql tuningOracle sql tuning
Oracle sql tuning
 
lab56_db
lab56_dblab56_db
lab56_db
 
PHP with MySQL
PHP with MySQLPHP with MySQL
PHP with MySQL
 
My sql Syntax
My sql SyntaxMy sql Syntax
My sql Syntax
 
PHP and MySQL.ppt
PHP and MySQL.pptPHP and MySQL.ppt
PHP and MySQL.ppt
 
P H P Part I I, By Kian
P H P  Part  I I,  By  KianP H P  Part  I I,  By  Kian
P H P Part I I, By Kian
 
Php
PhpPhp
Php
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
 
Mysql
MysqlMysql
Mysql
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
PHP 5 + MySQL 5 = A Perfect 10
PHP 5 + MySQL 5 = A Perfect 10PHP 5 + MySQL 5 = A Perfect 10
PHP 5 + MySQL 5 = A Perfect 10
 
Php Data Objects
Php Data ObjectsPhp Data Objects
Php Data Objects
 

Plus de Vineet Kumar Saini (20)

Abstract Class and Interface in PHP
Abstract Class and Interface in PHPAbstract Class and Interface in PHP
Abstract Class and Interface in PHP
 
Add edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHPAdd edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHP
 
Introduction to Html
Introduction to HtmlIntroduction to Html
Introduction to Html
 
Computer Fundamentals
Computer FundamentalsComputer Fundamentals
Computer Fundamentals
 
Country State City Dropdown in PHP
Country State City Dropdown in PHPCountry State City Dropdown in PHP
Country State City Dropdown in PHP
 
Stripe in php
Stripe in phpStripe in php
Stripe in php
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
Install Drupal on Wamp Server
Install Drupal on Wamp ServerInstall Drupal on Wamp Server
Install Drupal on Wamp Server
 
Joomla 2.5 Tutorial For Beginner PDF
Joomla 2.5 Tutorial For Beginner PDFJoomla 2.5 Tutorial For Beginner PDF
Joomla 2.5 Tutorial For Beginner PDF
 
Functions in PHP
Functions in PHPFunctions in PHP
Functions in PHP
 
Sorting arrays in PHP
Sorting arrays in PHPSorting arrays in PHP
Sorting arrays in PHP
 
Dropdown List in PHP
Dropdown List in PHPDropdown List in PHP
Dropdown List in PHP
 
Update statement in PHP
Update statement in PHPUpdate statement in PHP
Update statement in PHP
 
Delete statement in PHP
Delete statement in PHPDelete statement in PHP
Delete statement in PHP
 
Implode & Explode in PHP
Implode & Explode in PHPImplode & Explode in PHP
Implode & Explode in PHP
 
Types of Error in PHP
Types of Error in PHPTypes of Error in PHP
Types of Error in PHP
 
Database connectivity in PHP
Database connectivity in PHPDatabase connectivity in PHP
Database connectivity in PHP
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
Operators in PHP
Operators in PHPOperators in PHP
Operators in PHP
 
Variables in PHP
Variables in PHPVariables in PHP
Variables in PHP
 

Dernier

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 

Dernier (20)

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 

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