MySql database query results output PHP code example in a table. mysql Query result _ PHP Tutorial

Source: Internet
Author: User
MySql database query results use a table to output PHP code samples and mysql Query results. MySql database query results use a table to output PHP code samples. mysql Query results are displayed on common websites, in many databases, table data is displayed in the browser in MySql database query results. use tables to output PHP code samples and mysql Query results.

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:

<? Php // displays table data in a table. Common methods include 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 echo "test Database ". "$ table_name ". "all user data in the table is as follows:
"; Echo" total ". $ rows." row ". $ 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 ") ;?>

In general websites, we usually see that the table data in many databases appears in the browser...

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.