php+mysqli realizes the method of printing a table information in the database into a table, mysqli table
The example in this article describes the method of php+mysqli to print the information of a table in the database (including the header) into the table. Share it with everyone for your reference. The details are as follows:
Just take a look at this code. Need to learn the basics. The code is as follows:
Copy code The code is as follows:
$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);
//Get the total number of rows and columns returned
echo "Total: ".$res->num_rows." rows; Total: ".$res->field_count." columns.";
//Get the header---take it out from $res
echo "
";
while($field=$res->fetch_field()){
echo "{$field->name} | ";
}
echo "
";
//Loop to retrieve data
while($row=$res->fetch_row()){
echo "";
foreach($row as $value){
echo "$value | ";
}
echo "
";
}
echo "
";
$res->free();
}
showTable($mysqli,"news");
?>
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/949459.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/949459.htmlTechArticlephp+mysqli realizes the method of printing the information of a table in the database into a table. The example of this article about mysqli table is described php+mysqli prints a table information (including the header) in the database to...