This article mainly introduces how to use php + mysqli to print a table in the database to a table. It involves the related techniques of mysqli query. For more information, see
This article mainly introduces how to use php + mysqli to print a table in the database to a table. It involves the related techniques of mysqli query. For more information, see
This example describes how to print a table (including the table header) in a database using php + mysqli. Share it with you for your reference. The details are as follows:
This code will show you. Basic knowledge is required. The Code is as follows:
The Code is as follows:
<? Php
$ Mysqli = new MySQLi ("localhost", "root", "123456", "liuyan ");
If (! $ Mysqli ){
Die ($ mysqli-> error );
}
Function showTable ($ mysqli, $ table_name ){
$ SQL = "select * from $ table_name ";
$ Res = $ mysqli-> query ($ SQL );
// Obtain the total number of returned rows and columns
Echo "Total:". $ res-> num_rows. "row; total:". $ res-> field_count. "column. ";
// Retrieve the header --- retrieve from $ res
Echo"
";While ($ field = $ res-> fetch_field ()){Echo"
| {$ Field-> name} | ";}Echo"
";// Cyclically retrieve dataWhile ($ row = $ res-> fetch_row ()){Echo"
";Foreach ($ row as $ value ){Echo"
| $ Value | ";}Echo"
";}Echo"
";
$ Res-> free ();
}
ShowTable ($ mysqli, "news ");
?>
I hope this article will help you with php programming.
,