Home > Backend Development > PHP Tutorial > PHP+mysqli realizes the method of printing the information of a table in the database into a table, mysqli table_PHP tutorial

PHP+mysqli realizes the method of printing the information of a table in the database into a table, mysqli table_PHP tutorial

WBOY
Release: 2016-07-13 10:08:51
Original
960 people have browsed it

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 "";
}
echo "";
//Loop to retrieve data
while($row=$res->fetch_row()){
echo "";
foreach($row as $value){
echo "";
}
echo "";
}
echo "
{$field->name}
$value
";
$res->free();
}
showTable($mysqli,"news");
?>

I hope this article will be helpful to everyone’s PHP programming design.

www.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...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template