<p>04级新生名单</p> <table border="1" width="80%" cellpadding="0"> <tr> <td width="10%" align="center">Id</td> <td width="20%" align="center">Name</td> <td width="10%" align="center">Age</td> <td width="10%" align="center">Sex</td> <td width="30%" align="center">Address</td> <td width="20%" align="center">DoWith</td> </tr> <?php //连接数据库 //打开一个连接,连接到本地mysql数据库 $conn=mysql_connect("localhost","root","dalyluo");//ip,user,pwd //选择操作的资料库 mysql_select_db("test",$conn);// 资料库名称,连接 $sql="select * from student"; //用mysql_query函数从资料库中查询 mysql_query("set names gbk");//处理中文乱码问题,gbk可以是其它值 $result=mysql_query($sql,$conn);// search sql, connection //循环读取记录 while($row=mysql_fetch_array($result)){ ?> <tr> <td width="10%" align="center"><?php echo $row["stuid"] ?></td> <td width="20%" align="center"><?php echo $row["stuname"] ?></td> <td width="10%" align="center"><?php echo $row["stuage"] ?></td> <td width="10%" align="center"><?=$row["stusex"]?></td> <td width="30%" align="center"><?=$row["stuaddress"]?></td> <td width="20%" align="center"><a href="#" mce_href="#" onClick="<?php doDel($row["stuid"]) ?>">删除</a></td> </tr> <?php } //关闭连接 mysql_close($conn); function doDel($sid){ global $conn; mysql_select_db("test",$conn); $del_sql="delect from student where stuid="+$sid; mysql_query($del_sql,$conn); } ?> </table>