MySql database query result output in a table PHP code example _ PHP Tutorial

Source: Internet
Author: User
Tags php sample code
Use a table to output PHP sample code for MySql database query results. MySql database query results use a table to output PHP code samples this article mainly introduces the MySql database query results using a table to output PHP code samples. This article provides a code example directly, the required MySql database query results can be used to output the PHP code example in a table.

This article mainly introduces the PHP sample code output using a table in the MySql database query results. This article provides the sample code directly. For more information, see

In general websites, we usually see that the table data in many databases is displayed in the table in the browser. it is amazing at first, but it is not too complicated to think about it carefully, since dql and dml can be returned in a table, it is not a problem. However, it is worth noting that it is wrong to design a script on the client to implement the problem, even if it can be implemented, it is very complicated. Therefore, you can only consider the server and think about how to solve the problem. that is, print the table tag and the corresponding attribute and attribute value when returning the result, although this method does not seem reasonable, it is also the most effective method. The specific code is as follows:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

// Displays table data in a table.

Function ShowTable ($ table_name ){

$ Conn = mysql_connect ("localhost", "root", "toor ");

If (! $ Conn ){

Echo "connection failed ";

}

Mysql_select_db ("test", $ conn );

Mysql_query ("set names utf8 ");

$ SQL = "select * from $ table_name ";

$ Res = mysql_query ($ SQL, $ conn );

$ Rows = mysql_affected_rows ($ conn); // Obtain the number of rows

$ Colums = mysql_num_fields ($ res); // Obtain the number of columns

All user data in the echo "test Database". "$ table_name". "table is as follows:
";

Echo "total". $ rows. "row". $ colums. "columns
";

Echo"

For ($ I = 0; $ I <$ colums; $ I ++ ){

$ Field_name = mysql_field_name ($ res, $ I );

Echo"

}

Echo"

While ($ row = mysql_fetch_row ($ res )){

Echo"

For ($ I = 0; $ I <$ colums; $ I ++ ){

Echo"

}

Echo"

}

Echo"

"; "; "; "; "; ";
$ Field_name
$ Row [$ I]
";

}

ShowTable ("test1 ");

This article mainly introduces the PHP sample code output using tables in MySql database query results. This article provides the sample code directly...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.