作业:
查询INFO表所有数据,显示在页面上(表格)
性别要显示男女 民族 显示民族名称
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>无标题文档</title>
6 </head>
7 <body>
8
9 <table width="1000px" cellpadding="1" border="1"ellspacing="1">
10 <tr>
11 <td>编号</td>
12 <td>姓名</td>
13 <td>性别</td>
14 <td>名族</td>
15 <td>出生日期</td>
16 </tr>
17 <?php
18 //造对象
19 $db=new MySQLi("localhost","root","","hr.sql");
20 //判断连接是否出错
21 !mysqli_connect_error() or die("连接失败!");
22 //写SQL语句
23 $sql="select * from info";
24
25 //执行SQL
26 $result=$db->query($sql);
27
28 //从结果集对象中读取数据
29 while($attr=$result->fetch_row())
30 {
31 $attr[2]=$attr[2]=="1"?"男":"女";
32
33 $sql="select name from nation where code ='{$attr[3]}'";
34 $we=$db->query($sql);
35 $mz=$we->fetch_row();
36
37 echo "<tr>
38 <td>{$attr[0]}</td>
39 <td>{$attr[1]}</td>
40 <td>{$attr[2]}</td>
41 <td>{$mz[0]}</td>
42 <td>{$attr[4]}</td>
43 </tr>";
44
45
46
47
48 }
49
50
51 ?>
52
53
54
55
56
57
58 </body>
59 </html>
显示的结果: