Sample PHP code output using a table in MySql database query results

Source: Internet
Author: User
Tags php sample code
This article mainly introduces the PHP sample code output using a table in MySql database query results. This article provides sample code directly. if you need a friend, you can refer to it on a general website, in many databases, the table data 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 generally returned, it should not be a problem to return data in a table. However, it is worth noting that it is wrong to design scripts on the client to implement the problem. even if it can be implemented, it is very complicated, you can only consider the server and think about how to solve the problem. that is, you can print the table label and corresponding attributes and attribute values when returning the result. Although this method does not seem reasonable, but this 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 ") ;?>

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.