MySQL database query results table output PHP code example _php Tutorial

Source: Internet
Author: User

MySQL database query results tabular output PHP code example


This article mainly introduces the MySQL database query results with the table output PHP code example, this article directly gives the code example, the need for friends can refer to the following

In the general Web site, we will usually see that many of the database table data in the browser appears in the table, the beginning to feel very magical, but it is not too complicated to think carefully, since it is possible to DQL and DML General return, returned in a tabular manner should not be a problem, but, one thing is, In the client design script to implement the problem is not right, even if it can be implemented is very complex, so, only in the context of the server, think about the way the problem solved, that is, when returning to print the table label and corresponding attributes and property values, although this way seems unreasonable, But this is also the most effective way. 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

21st

22

23

24

25

26

27

28

29

30

31

32

33

Display the table's data in a table, common ways

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);//Gets the number of rows

$colums =mysql_num_fields ($res);//Gets the number of columns

echo "Test database". " $table _name "." All user data for the table is as follows:
";

echo "Total". $rows. " Line ". $colums." Column
";

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");

http://www.bkjia.com/PHPjc/971949.html www.bkjia.com true http://www.bkjia.com/PHPjc/971949.html techarticle MySQL database query results using tabular output PHP code example this article mainly introduces the MySQL database query results with tabular output PHP code example, this article directly gives the code example, the need for friends ...

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