Home  >  Article  >  php教程  >  php+mysqli实现将数据库中一张表信息打印到表格里的方法

php+mysqli实现将数据库中一张表信息打印到表格里的方法

WBOY
WBOYOriginal
2016-06-06 20:12:00946browse

这篇文章主要介绍了php+mysqli实现将数据库中一张表信息打印到表格里的方法,涉及mysqli查询的相关技巧,需要的朋友可以参考下

本文实例讲述了php+mysqli实现将数据库中一张表信息(包括表头)打印到表格里的方法。分享给大家供大家参考。具体如下:

这段代码将就看吧。需要学习基础知识。代码如下:

复制代码 代码如下:

$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);
 //获取返回总行数和列数
 echo "共有:".$res->num_rows."行;共有:".$res->field_count."列。";
 //获取表头---从$res取出
 echo "

";
 while($field=$res->fetch_field()){
   echo "";
 }
 echo "";
 //循环取出数据
 while($row=$res->fetch_row()){
  echo "";
  foreach($row as $value){
   echo "";
  }
  echo "";
 }
 echo "
{$field->name}
$value
";
 $res->free();
}
showTable($mysqli,"news");
?>

希望本文所述对大家的php程序设计有所帮助。

Statement:
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