黑马程序员技术交流社区

标题: 2032-李志颖-4-27-视频课 [打印本页]

作者: 温存另一半的爱    时间: 2017-4-29 00:18
标题: 2032-李志颖-4-27-视频课
调用数据库数据示例:
<--   conn.php-->
<?php
        $conn = mysql_connect("localhost","root","");   //连接数据库
        mysql_query("set names utf8");    // 设置编码
        mysql_select_db("test",$conn);  //选择使用的数据库
?>
以上是conn.php

<?php
        require("conn.php");   // 调用conn.php
        $result= mysql_query("select * from student ", $conn);    //创建结果集
        $row = mysql_fetch_assoc($result);        //将结果集数据放到row数组中
?>
<table border ="1" width="95%">
        <tr bgcolor = "#e0e0e0">
                <th width="80">学号</th><th width="60">姓名</th>  
                <th width ="60">性别</th><th width ="100">出生日期</th>
                <th width ="60">籍贯</th><th width ="60">班级ID</th>
        </tr>
        <? while($row = mysql_fetch_assoc($result)){ ?>   // 循环输出记录在页面上
                <tr><td><?=$row['sno']?></td><td><?=$row['sname']?> </td>
                        <td><?=$row['sex']?></td><td><?=$row['birthdate']?> </td>
                        <td><?=$row['birthPlace']?> </td><td><?=$row['classId']?> </td></tr>
                        <? }?>
</table>







欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2