Home > Article > Backend Development > How to query mysql data in php and display it
How to query and display mysql data in php: first create a table in the database and insert multiple pieces of data; then create a file, use the header method to set the encoding format of the page to [utf-8]; then select the Operate the database and convert the result set data into array form; finally open the file in the browser to view the results.
How to query and display mysql data in php:
1. Create a data table in the mysql database , insert multiple pieces of data into the table for testing.
#2. Create a test.php file, and within the file, use the header() method to set the encoding format of the page to utf-8.
3. In the test.php file, connect to the mysql database and use mysqli_select_db to select the database to operate.
4. In the test.php file, create a sql statement to query the data table, and use the mysqli_query function to execute the sql statement.
5. In the test.php file, use the mysqli_fetch_assoc function to convert the result set data into array form, and loop the array elements through the while statement.
#6. In the while loop, call the array array and use echo to output.
7. Open the test.php file in the browser and view the results.
Related free learning recommendations: php programming (video)
The above is the detailed content of How to query mysql data in php and display it. For more information, please follow other related articles on the PHP Chinese website!