Home > Article > Backend Development > How to query 10 pieces of data each time in php
How to query 10 pieces of data in php each time: 1. Create a user table in the mysql database; 2. Connect to the mysql database and use mysqli_select_db to select the database; 3. Only query the first 10 pieces through limit; 4. Use the while statement to loop through the data output.
#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.
How does php query 10 pieces of data each time?
php mysql implementation only queries the first 10 pieces of data:
In the mysql database, create a user table and insert multiple pieces of data into the table for test.
Create a test.php file, and within the file, use the header() method to set the encoding format of the page to utf-8.
In the test.php file, connect to the mysql database and use mysqli_select_db to select the database to operate.
In the test.php file, use select to create a sql statement, and limit the query to only the first 10 items through limit, and then use the mysqli_query function to execute the sql statement.
In the test.php file, use the mysqli_fetch_assoc function to convert the result set data into an array form, and output the data through a while statement loop.
Open the test.php file in the browser to view the results.
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to query 10 pieces of data each time in php. For more information, please follow other related articles on the PHP Chinese website!