Home  >  Article  >  Backend Development  >  How to query mysql data in php and display it

How to query mysql data in php and display it

coldplay.xixi
coldplay.xixiOriginal
2020-11-04 15:06:389287browse

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 mysql data in php and display it

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.

How to query mysql data in php and display it

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

How to query mysql data in php and display it

3. In the test.php file, connect to the mysql database and use mysqli_select_db to select the database to operate.

How to query mysql data in php and display it

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.

How to query mysql data in php and display it

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.

How to query mysql data in php and display it

#6. In the while loop, call the array array and use echo to output.

How to query mysql data in php and display it

7. Open the test.php file in the browser and view the results.

How to query mysql data in php and display it

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn