The example in this article describes how the PHP+MYSQLI implementation prints a table information in a database (including the header) to a table. Share to everyone for your reference. Specifically as follows:
This piece of code will look at it. Need to learn basic knowledge. The code is as follows:
Copy 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 "Altogether:". $res->num_rows. " All: ". $res->field_count." Column. ";
Get header---Remove from $res
echo "<table border=1><tr>";
while ($field = $res->fetch_field ()) {
echo "<th>{$field->name}</th>";
}
echo "</tr>";
Looping out data
while ($row = $res->fetch_row ()) {
echo "<tr>";
foreach ($row as $value) {
echo "<td> $value </td>";
}
echo "</tr>";
}
echo "</table>";
$res->free ();
}
Showtable ($mysqli, "News");
?>
I hope this article will help you with your PHP programming.