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 8 <body> 9 <?php 10 $db=new MySQLi("localhost","root","3177389","my test"); 11 !mysqli_connect_error()or die("连接失败"); 12 $sql="select * from Info"; 13 $result=$db->query($sql); 14 $attr=$result->fetch_all(); 15 echo"<table width=‘100%‘ border=‘1‘ cellpadding=‘0‘ cellspacing=‘0‘>"; 16 echo "<tr><td>代号</td><td>姓名</td><td>性别</td><td>民族</td><td>生日</td></tr>"; 17 for ($i=0;$i<count($attr);$i++) 18 {$sex=$attr[$i][2]?"男":"女"; 19 $name=shownation ($db, $attr[$i][3]); 20 echo "<tr><td>{$attr[$i][0]}</td><td>{$attr[$i][1]}</td><td>{$sex}</td><td>{$name}</td><td>{$attr[$i][4]}</td></tr>"; 21 } 22 23 24 25 echo "</table>"; 26 function shownation ($db,$code) 27 { 28 29 $sqla="select Name from nation where Code=‘{$code}‘"; 30 $resulta=$db->query($sqla); 31 $jieguo=$resulta->fetch_row(); 32 return $jieguo[0]; 33 34 } 35 ?> 36 </body> 37 </html>
时间: 2024-10-03 13:53:38