PHP导出数据库的表数据

 

 1 <?php
 2 @mysql_connect("localhost","root","123456")or die;    //链接数据库
 3 @mysql_select_db("test1")or die;    //选择数据库
 4 $query = @mysql_query("select * from yonghu")or die;    //查询‘yonghu’表中的所有记录
 5 echo "<table border=1><tr align=center><th>用户名</th><th>性别</th><th>出生日期</th><th>邮箱</th></tr>";
 6 $n=0;
 7 while ($row = mysql_fetch_array($query))    //遍历‘yonghu’表中的数据,并形成数组
 8 {
 9     $username = $row['username'];    //使用键获取数组中对应的值
10     $sex = $row['sex'];
11     $birth = $row['birth'];
12     $email = $row['email'];
13     echo "<tr>";
14     echo "<td>{$username}</td>";    //按照数据表的列在表格里输出对应数据
15     echo "<td>{$sex}</td>";
16     echo "<td>{$birth}</td>";
17     echo "<td>{$email}</td>";
18     echo "</tr>";
19     $n++;
20 /*    if($n>14){
21         return;
22     }*/
23 }    
24 echo "<table>";
25 ?>

 

posted @ 2016-11-27 23:53  Oink  阅读(6511)  评论(0编辑  收藏  举报