Home Tutorial Php Sql PHP SQL Limit

 
 

PHP SQL Limit
Posted on: December 10, 2010 at 12:00 AM
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 create 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. The output shows below:

 

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:

Related Tags for PHP SQL Limit:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.