PHP连接数据库建立表格作业
<table>
<tr>
<td>编号</td>
<td>姓名</td>
<td>性别</td>
<td>生日</td>
<td>班级</td>
</tr>
<?php
$db = new MySQLi("localhost","root","123","student");
!mysqli_connect_error() or die("链接失败!");
$sql = "select * from student";
$result = $db->query($sql);
while($attr = $result->fetch_row())
{
if($attr[2]==1)
{
$attr[2]="男";
}
else
{
$attr[2]="女";
}
echo "<tr>
<td>
{$attr[0]}
</td>
<td>
{$attr[1]}
</td>
<td>
{$attr[2]}
</td>
<td>
{$attr[3]}
</td>
<td>
{$attr[4]}
</td>
</tr>";
}
?>
</table>