Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Sql Mysql-example PHP SQL Limit

Related Tutorials


 
 

Share on Google+Share on Google+

PHP SQL Limit

Advertisement
This example illustrates how to execute LIMIT operator of mysql in PHP.

PHP SQL Limit

     

This example illustrates how to execute LIMIT operator of mysql in PHP. 

In this example, we have created a limit.php page, in which we execute a query with 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.

 

 

 

 

Table: emp

 

Source Code of limit.php 

<?php
  $con = mysql_connect("localhost","root","root");
  if (!$con) {
  die('Could not connect: ' . mysql_error());
  }

  mysql_select_db("test", $con);
  $result = mysql_query("select * from emp limit 0,5");
  echo "<table border='1'>
  <tr>
  <th>id</th>
  <th>Name</th>
  </tr>";
  while($row = mysql_fetch_array($result)) {
  echo "<tr>";
  echo "<td>" . $row['emp_id'] "</td>";
  echo "<td>" . $row['name'] "</td>";
  echo "</tr>";
  }
  echo "</table>";
  
  mysql_close($con);
?>

Download Source Code

 

Output:

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 20, 2009

Related Tutorials

Discuss: PHP SQL Limit  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com