Skip to main content

PHP Limit Data Selections In MySQL


In this tutorial, we are going to tackle about PHP Limit Data Selections From MySQL. We have to use a LIMIT function to specify the number of our data to display. You can use this codes if you have a pagination table to have multiple pages to minimize the size of your data table.

We are going to set the LIMIT of our data into 4. This is the code.

  1. <?php
  2. require_once('connection.php');
  3. $result = $conn->prepare("SELECT * FROM tbl_registration ORDER BY tbl_registration_id ASC LIMIT 4");
  4. $result->execute();
  5. for($i=0; $row = $result->fetch(); $i++){
  6. $id=$row['tbl_registration_id'];
  7. ?>

This is the output:

This is our data in the database table.

Result

After we code the LIMIT function in the SELECT Statements. The output looks like this:

Result

So what can you say about this work? Share your thoughts in the comment section below or email me at [email protected]. Practice Coding. Thank you very much.

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.