Php+mysqli implements the method of printing a table information in a database to a table, mysqli table
The example in this paper describes how Php+mysqli implements a method of printing a table information in a database, including a header, to a table. Share to everyone for your reference. Specific as follows:
This piece of code will look. Need to learn basic knowledge. The code is as follows:
Copy the Code code 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);
Gets the total number of rows and columns returned
echo "Total:". $res->num_rows. " ". $res->field_count." Column. ";
Get header---removed from $res
echo "
"; while ($field = $res->fetch_field ()) {echo "
{$field->name} | ";} echo "
"; Loop out data while ($row = $res->fetch_row ()) {echo "
"; foreach ($row as $value) {echo '
$value | "; } echo "
"; } echo "
";
$res->free ();
}
Showtable ($mysqli, "News");
?>
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/949459.html www.bkjia.com true http://www.bkjia.com/PHPjc/949459.html techarticle Php+mysqli implements the method of printing a table information in a database to a table, MYSQLI table This article describes the PHP+MYSQLI implementation of the database in a table information (including the table header) to print to ...