【上机实验】PHP操作MySQL数据查询
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template
<!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <?php #获取学号对应的专业名称 #连接数据库 $link = mysqli_connect('localhost','root','','教学管理'); if($link) { #获取数据库 $data = mysqli_select_db($link,'教学管理' ); #确保数据不会乱码 mysqli_set_charset($link, 'utf8'); if($data) { #选取数据--specialty $sql = 'SELECT * FROM specialty'; $result = mysqli_query($link, $sql); if($result) { $rs = mysqli_fetch_row($result); } else { echo 'fail to carry out MYSQL.'; } } else { echo 'fail to get database.'; } } else { echo 'fail to connect.'; } ?> <form action="#" method="post"> 请选择专业: <select name="sltzno"> <?php while($rs=mysqli_fetch_row($result)):?> <option value="<?=$rs[0]?>"><?=$rs[1]?></option> <?php endwhile;?> </select> <input type="submit" name="btn" value="查询"><br> </form> <?php #根据专业号显示学生信息 if(isset($_POST['btn'])) { $zno=$_POST['sltzno']; $link = mysqli_connect('localhost', 'root', '', '教学管理'); if($link) { $data = mysqli_select_db($link,'教学管理'); mysqli_set_charset($linkmysql查询, 'utf8'); if($data) { $sql = "SELECT * FROM student WHERE zno = '{$zno}'"; $result = mysqli_query($link,$sql); if($result) { while ($rs=mysqli_fetch_row($result)) { echo $rs[0]." ". $rs[1]." ".$rs[5]; echo '<hr>'; } } } } echo "一共有", mysqli_num_rows($result),"条数据"; } ?> </body> </html> '> (编辑:淮北站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |