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

How to query mysql data in php and display it

coldplay.xixi
Release: 2023-03-07 09:36:02
Original
9505 people have browsed 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 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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template