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