Php + mysqli: how to print a table in a database to a table

Source: Internet
Author: User
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" ";}Echo" ";// Cyclically retrieve dataWhile ($ 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 help you with php programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.