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