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 ?>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM