【php】3、学生管理系统-查看用户
来源:互联网 发布:linux高精度sleep方法 编辑:程序博客网 时间:2024/06/05 16:54
<?php include_once 'stuService.class.php'; session_start(); $name = $_SESSION['student_name']; if($name == "") { header("Location: stu_login.php?error=1"); exit(); } $pagesize = 20; $pagenow = 1; $pagecount = 0; $service = new stuservice(); $pagecount = $service->getpagecount($pagesize); if(!empty($_GET['pagenow'])) { $pagenow=$_GET['pagenow']; } $stulist = $service->getstulist($pagesize, $pagenow); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>学生成绩管理系统</title></head><body background="pic/bg.gif"> <form action="studentlist.php" method="get"><table width="767" height="644" border="0" align="center"><tr> <td height="228" colspan="5" background="pic/top.gif" /></tr><tr> <td height="22" colspan="5" background="pic/in_01.gif" /> </tr> <tr> <td height="28" background="pic/in_20.gif" /> <td background="pic/in_20.gif">学生ID号</td> <td background="pic/in_20.gif">学生姓名</td> <td background="pic/in_20.gif">学生密码</td> <td background="pic/in_20.gif"></td> </tr> <?php for($i = 0; $i < count($stulist); ++$i) { $row=$stulist[$i]; //取出第i行数据,显示出来 $passwd = md5($row['stu_password']); //学生进来不能看到密码 ?> <tr> <td background="pic/in_20.gif"></td> <td background="pic/in_20.gif"><?php echo stripslashes($row['stu_id']);?></td> <td background="pic/in_20.gif"><?php echo stripslashes($row['stu_name']);?></td> <td background="pic/in_20.gif"><?php echo stripslashes($passwd); ?></td> <td background="pic/in_20.gif"></td> </tr> <?php } echo "<tr>"; echo "<td background='pic/in_20.gif' />"; echo "<td background='pic/in_20.gif'>"; //显示上一页和下一页 if($pagenow > 1) { $prePage=$pagenow - 1; echo "<a href='studentlist.php?pagenow=$prePage'>上一页</a> "; echo "<a href='studentlist.php?pagenow=$prePage'>《《</a> "; } echo "</td>"; echo "<td background='pic/in_20.gif'>"; //中间打印10页选择 for($i=$pagenow; $i < $pagenow+10; ++$i) { if($i <= $pagecount) { echo "<a href='studentlist.php?pagenow=$i'>$i</a> "; } } echo "</td>"; echo "<td background='pic/in_20.gif'>"; //下一页 if($pagenow < $pagecount) { $nextPage=$pagenow+1; echo "<a href='studentlist.php?pagenow=$nextPage'>》》</a> "; echo "<a href='studentlist.php?pagenow=$nextPage'>下一页</a> "; } echo "</td>"; echo "<td background='pic/in_20.gif'>"; echo "当前页$pagenow/共{$pagecount}页面"; echo "</td>"; echo "</tr>"; ?> <tr> <td background="pic/in_20.gif"></td> <td background='pic/in_20.gif'> 跳转到:<input type="text" name="pagenow" /></td> <td background='pic/in_20.gif'><input type="submit" value="GO" /></td> <td background="pic/in_20.gif"></td> <td background="pic/in_20.gif"></td> </tr> </table> </form></body></html>
stuservice类
<?php//这个是对数据库中表student的操作 include_once 'mysql.class.php'; include_once 'student.class.php'; include_once 'confing.php'; class stuservice { //根据用户名和密码,查看个数 public function checkstunum($name, $password) { $mysql = new mysql(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $num=0; $sql = "select count(*) from student where stu_name = '".$name."' and stu_password = '".$password."'"; //执行命令 $res = $mysql->execute_dql($sql); $row=mysqli_fetch_row($res); if($row) { $num=$row[0]; } mysqli_free_result($res); $mysql->close_connect(); return $num; } //根据每页的大小,和当前的页面查询出所有的学生 public function getstulist($pagesize,$pagenow) { $mysql = new mysql(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $sql="select * from student limit ".($pagenow-1)*$pagesize.",$pagesize"; $res=$mysql->execute_dql($sql); $arr=array(); $i=0; while($row = mysqli_fetch_assoc($res)) { $arr[$i++]=$row; } mysqli_free_result($res); $mysql->close_connect(); return $arr; } //得到总页数 public function getpagecount($pagesize) {$mysql = new mysql(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);$sql="select count(stu_id) from student";$res=$mysql->execute_dql($sql);$i=0;$row = mysqli_fetch_row($res);if($row){$rowcount=$row[0];}$pagecount=ceil($rowcount/$pagesize); //返回不小于 value 的下一个整数,value 如果有小数部分则进一位。 mysqli_free_result($res);$mysql->close_connect();return $pagecount;}//根据学生姓名得到相应数据public function getstu($name){ $stu = new student(); $mysql = new mysql(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $sql="select * from student where stu_name='".$name."'"; $res=$mysql->execute_dql($sql); if($row = mysqli_fetch_assoc($res)) { $stu->setStu_id($row['stu_id']); $stu->setStu_name($row['stu_name']); $stu->setStu_password($row['stu_password']); } mysqli_free_result($res); $mysql->close_connect(); return $stu; }//根据id号获取userpublic function getstubyid($id){ $stu = new student(); $mysql = new mysql(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $sql="select * from student where stu_id='".$id."'"; $res=$mysql->execute_dql($sql); if($row = mysqli_fetch_assoc($res)) { $stu->setStu_id($row['stu_id']); $stu->setStu_name($row['stu_name']); $stu->setStu_password($row['stu_password']); } mysqli_free_result($res); $mysql->close_connect(); return $stu;}//根据得到的对象修改数据库中的值public function update(student $stu){ $mysql = new mysql(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $sql="update student set stu_name='".$stu->getStu_name()."',stu_password='".$stu->getStu_password()."' where stu_id=".$stu->getStu_id(); $b = $mysql->execute_dml($sql);// if($b == 1)// {// return true;// } return $b;}//删除用户public function delete(student $stu){ $mysql = new mysql(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $sql = "delete from student where stu_id=".$stu->getStu_id().";"; $b = $mysql->execute_dml($sql); return $b;} }?>
mysql类
<?php// include_once 'confing.php'; class mysql extends mysqli {// public $link;// public $db_host = DB_HOST;// public $db_user = DB_USER;// public $db_password = DB_PASSWORD;// public $db_name = DB_NAME;public function __construct($host, $user, $pass, $db){ parent::__construct($host, $user, $pass, $db); if (mysqli_connect_error()) { die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); }// $this->link = new mysqli($this->db_host, $this->db_user, $this->db_password, $this->db_name);// if(!$this->link){// die("连接失败".mysql_error());// }//mysql_select_db($this->dbname,$this->link);}//执行SQL语句得到结果集,查询语句public function execute_dql($sql){ $res = $this->query($sql) or die(mysqli_error($this)); return $res;}//执行SQLdml语句插入,更新,删除public function execute_dml($sql){ $b = $this->query($sql) or die(mysqli_error($this)); if(!$b) { return 0; } else { if($this->affected_rows > 0) //如果收影响的行数大于0 { return 1; //OK了 } else { return 2; //没有行收到影响 } }}//关闭连接public function close_connect(){ if(!empty($this)) $this->close();} } ?>
student类
<?php class student { private $stu_id; private $stu_name; private $stu_password; /** * @return the $stu_id */ public function getStu_id() { return $this->stu_id; } /** * @return the $stu_name */ public function getStu_name() { return $this->stu_name; } /** * @return the $stu_password */ public function getStu_password() { return $this->stu_password; } /** * @param field_type $stu_id */ public function setStu_id($stu_id) { $this->stu_id = $stu_id; } /** * @param field_type $stu_name */ public function setStu_name($stu_name) { $this->stu_name = $stu_name; } /** * @param field_type $stu_password */ public function setStu_password($stu_password) { $this->stu_password = $stu_password; } } ?>
config.php配置数据库
<?php//用define定义常量//连接服务器define('DB_HOST', 'localhost');//连接数据库的账号define('DB_USER', 'root');//连接数据库的密码define('DB_PASSWORD', 'xiaofeng2015');//连接数据库的名字define('DB_NAME', 'studentmanage');//?>
预览:
0 0
- 【php】3、学生管理系统-查看用户
- 【php】7、学生管理系统-管理员查看用户
- 【php】8、学生管理系统-查看管理员
- PHP 学生管理系统实现
- 学生管理系统3
- 【php】1、学生管理系统-欢迎界面
- 【php】2、学生管理系统-登陆进去
- 【php】4、学生管理系统-修改界面
- 【php】6、学生管理系统-登陆进去
- 【php】9、学生管理系统项目
- 学生管理系统--用户登录窗体创建总结
- 【php】5、学生管理系统-管理员欢迎界面
- php基于thinkphp3.x的学生社团管理系统
- 学生信息系统学习心得三、学生1.5系统用户管理模块的创建
- 学生管理系统之BUG(3)
- 一个学生管理系统
- 学生同学录管理系统
- 学生管理系统
- 【转】51单片机精确延迟程序
- Linux开发常用命令
- [G+smo]单元和边界迭代器 iterators
- JSP中自定义标签
- firstChild,lastChild,NextSibling,previousSibling的使用
- 【php】3、学生管理系统-查看用户
- html 为控件添加注释(鼠标悬停即显示)
- [G+smo]mapping 几何映射
- 结构体对齐详解
- [G+smo]Boundary conditions
- 黑马程序员__操作符
- 7.1.1 除法【还没弄出来】
- 公司一个月(总结)
- HDU1016 Prime Ring Problem