Skip to main content

PHP Limit Data Selections In MySQL

Screenshot
Body

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

This is the output:

This is our data in the database table.

ResultAfter 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.

Add new comment