This article describes how to print a table in a database to a table using php + mysqli, and describes how to query mysqli, for more information about how to use php + mysqli to print a table (including the table header) in a database to a table. 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.