Member-only story
Select the first 10 rows from MySQL using PHP
Hi friends, in this tutorial, you will learn how to select the first 10 rows from MySQL using PHP. This kind of query is required very often when you need a certain number of rows from your MySQL database to display in the application or in the browser.
Also read, Delete a row in MySQL
There are various methods in MySQL such as PDO, MySQLi, etc by which we can do this. To do this, you can use two approaches of MySQL query as mentioned in the below steps.
Steps to select First 10 Rows from MySQL using PHP
Step 1:- First of all, create an HTML file inside the root directory of your local server.
Step 2:- Set up the database connection to your MySQL database as shown below
<?php
$servername='localhost';
$username="root";
$password="";
$dbname="myproject_db";
// Create connection
$con = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
?>
Step 3:- Create a table in the MySQL database as shown below
DDL information of the table
CREATE TABLE employee (
…
id int(10) NOT NULL AUTO_INCREMENT,
name varchar(255) COLLATE utf8mb4_unicode_ci NOT