基于php的选课系统设计(含源文件)
歡迎添加微信互相交流學習哦!
項目源碼:https://gitee.com/oklongmm/biye
摘要:本文以一個具體的應用系統(tǒng)—學生選課信息系統(tǒng)的設(shè)計與實現(xiàn)來說明如何利用b/s技術(shù)和php技術(shù)來設(shè)計和構(gòu)建web應用。b/s技術(shù)技術(shù)的使用能提高開發(fā)效率,增加系統(tǒng)的易維護性。并用到了以 thinkPHP為基礎(chǔ)的框架編程技術(shù)和以mysql為基礎(chǔ)的數(shù)據(jù)庫應用技術(shù)。
?
?
?
關(guān)鍵詞: B/S技術(shù); PHP;WEB應用;MVC技術(shù)。
?
?
?
?
?
Abstract:In this paper, a specific application - Student Elective Information System Design and Implementation to illustrate how to use the b / s technology and php techniques to design and build web applications. b / s technology, the use of technology can improve development efficiency, increase system maintainability. And the use of the thinkPHP-based framework with programming techniques and mysql-based database application technology.
?
?
?
?
Keywords:B/S technology; PHP; WEB applications; MVC technology
?
?
?
?
?
?
?
?
?
?
1引言:
現(xiàn)在信息管理系統(tǒng)軟件的開發(fā),采用b/s技術(shù)可以提高效
率,這樣可以極大的提高開發(fā)效率,保證系統(tǒng)開發(fā)的易維護性。Php又是一個開源免費流行的動態(tài)web編程技術(shù),本文用b/s技術(shù)和php技術(shù)來設(shè)計和實現(xiàn)一個系統(tǒng)。
?
?
2系統(tǒng)分析
本系統(tǒng)設(shè)計為學生通過網(wǎng)頁登陸學校網(wǎng)站,進行選課,管理老師也可以通過網(wǎng)頁登陸進行管理和發(fā)布課程,管理員賬號用于學生賬號和老師賬號的管制,并且一般的計算機都有瀏覽器終端,很方便實用。Apache+Php+mysl服務器系統(tǒng)可移植性強,搭建方便,開源免費。
?
?
2.1下面用例圖來說明該系統(tǒng)要實現(xiàn)的功能
?
?
?
?
?
?
?
2.2系統(tǒng)總體結(jié)構(gòu)
本系統(tǒng)采用三層體系結(jié)構(gòu),分為表示層,事務處理層,數(shù)據(jù)存
儲層。三層結(jié)構(gòu)層次清晰,易維護。
表示層:有每個用戶用的pc機上的瀏覽器向用戶提供圖形界面,操作選項等,供用戶選擇,使用。Pc機一端連接用戶,一段連接網(wǎng)絡(luò)另一端的服務器。
事務處理層:事務處理層由Apache+php動態(tài)服務器完成,Apache+php動態(tài)服務器按照事先編好的php腳本,處理分別來自pc機用戶端和數(shù)據(jù)庫的數(shù)據(jù)往來。
數(shù)據(jù)存儲層:數(shù)據(jù)存儲層由mysql數(shù)據(jù)庫完成,負責保存和高效回應來自服務器的請求。使數(shù)據(jù)實現(xiàn)有組織的高效管理。
?
3 模塊的設(shè)計和實現(xiàn)
在php的基礎(chǔ)上應用thinkphp框架結(jié)構(gòu)實現(xiàn),實現(xiàn)程序的模塊化,控制器和網(wǎng)頁的模板化。
部分模塊實例:
<?php
//以下為后臺模塊的操作
class IndexAction extends Action{????????? //繼承有thinkphp提供的控制基礎(chǔ)類
??? function _initialize(){??? //初始化模塊
??? ?? header("Content-type:text/html;charset=utf-8");
??? }
??? function index(){?????????? //入口模塊
??????? $url=U("login");
??? ?? header("Location:$url");
??? }
??? function login(){????? //登錄模塊
??? ?? $this->display();
??? }
??? function check_logined(){??? //檢測是否已經(jīng)登錄,注意跟下面的判斷是否登錄成功是不同的,這個要調(diào)用在各個頁面中。
??? ?? session_start();
??? ?? $user=M('Admin');
??? ?? $condition['username']=$_SESSION['username'];
??? ?? $us=$user->where($condition)->find();
??????? if(!$us){$url=U('login');$this->assign("jumpUrl",$url);$this->error("還未登陸");}
??? }
??? function admin() {???? //后臺管理首頁
??? ?? $this->check_logined();
??? ?? $date=date("Y年m月d日",time());
??? ?? $this->assign(date,$date);
??? ?? $this->assign('username',$_SESSION['username']);
??? ?? $this->display();
?
??? }
??? function siteinfo(){? //后臺管理的首頁信息
??? ?? $this->check_logined();
??? ?? $this->display();
??? }
??? function check_login(){?????? //判斷是否登錄成功
??? ?? session_start();
??? ?? $user=M('Admin');
??? ?? if(!$data=$user->create()){
??? ?????? $this->error("登錄失敗");
??? ?? }
??? ?? $condition['username']=$data['username'];
??? ?? $us=$user->where($condition)->find();
??? ?? if(!$us){ $this->error("用戶名或者密碼錯誤!!");}
??? ?? if($us['password']!=md5($data['password'])){$this->error("用戶名或者密碼錯誤!!");}
??? ?? $_SESSION['username']=$data['username'];
??? ?? $this->assign("jumpUrl",U('admin'));
??? ?? $this->success("登錄成功");
??? }
??? function admin_exit(){????? //退出系統(tǒng)
??? ?? $this->check_logined();
??? ?? unset($_SESSION['username']);
??? ?? $this->assign("jumpUrl",U('login'));
??? ?? $this->success("退出成功");
??? }
??? function manageStuInfo(){???? //管理學生信息
??? ?? $this->check_logined();
??? ?? $stu=M("Student");
??? ?? $count=$stu->count();
??? ?? $listRows=10;
??????? import("ORG.Util.Page");
??????? $p=new Page($count,$listRows);
??????? $limit_options=$p->firstRow.",".$p->listRows;
??? ?? $stu_info=$stu->order("id desc")->limit($limit_options)->findAll();
??? ?? $page=$p->show();
??? ?? $this->assign("page",$page);
??? ?? $this->assign("pagestyle","green-black");
??? ?? $this->assign("stu_info",$stu_info);
??? ?? $this->display();
??? }
??? function editStuInfo(){????? //編輯學生信息
??????????? $this->check_logined();
??????????? $stu=M("Student");
??????????? $id=$_GET['id'];
??????????? if(empty($id))?? $this->error("參數(shù)為空");
??????????? $stuInfo=$stu->where("id=$id")->find();
??????????? $checked="";
??????????? if($stuInfo[sex]=="女") $checked="checked";
??????????? $this->assign("checked",$checked);
??????????? $this->assign("stuInfo",$stuInfo);
??????????? $this->display();
??? }
??? function updateStuInfo(){??? //更新學生信息
??????? $this->check_logined();
??????? $stu=M('Student');
??? ?? $id=$_GET['id'];
??? ?? if(!$data=$stu->create()){
??? ?????? $this->error("修改失敗");
??? ?? }
??? ?? if(!$stu->where("id=$id")->save($data)){
??? ?????? $this->error("修改失敗");
??? ?? }
??? ?? $this->success("修改成功");
??? }
??? function deleteStuInfo(){????? //刪除學生信息
? ???? ?$this->check_logined();
??? ?? ?$id=$_GET['id'];
??? ?? ?$condition['id']=$id;
??? ?? ?$stu=M('Student');
??? ?? ?if(!$stu->where($condition)->limit('1')->delete()){
??? ?? ??? $this->error("刪除失敗");
??? ?? ?}
??? ?? ?$selected=M("selected");
??? ?? ?if($selected_info=$selected->where("stu_id=$id")->select()){
??? ?? ??? ?$selected->where("stu_id=$id")->delete();??? //如果這個學生有選課信息,把該學生選課信息刪除掉。
??? ?? ??? ?for($i=0;$i<count($selected_info);$i++){
??? ?? ??? ??? ?$course_id[$i]=$selected_info[$i]['course_id'];
??? ?? ??? ?}
??? ?? ??? ?$course=M("Course");
??? ?? ??? ?$map['id']=array("in",$course_id);
??? ?? ??? ?$course->setDec("selectedMan",$map);?? //并把這個學生選的課的已選人數(shù)減少一個。
??? ?? ?}
??? ?? ?$this->success("刪除成功");
……………………?>
?
4數(shù)據(jù)庫的設(shè)計和實現(xiàn)
4.1表設(shè)計:
課程表:
學生教師表:
管理員表:
4.2表的實現(xiàn)(包括錄入預設(shè)信息)
采用mysql命令,在數(shù)據(jù)庫查詢中輸入sql命令并運行。
?
SET FOREIGN_KEY_CHECKS=0;
DROP TABLE IF EXISTS `info_admin`;
CREATE TABLE `info_admin` (
? `username` varchar(20) NOT NULL,
? `password` varchar(50) default NULL,
? PRIMARY KEY? (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=gb2312;
?
-- ----------------------------
-- ----------------------------
INSERT INTO `info_admin` VALUES ('admin', '21232f297a57a5a743894a0e4a801fc3');
?
-- ----------------------------
-- ----------------------------
DROP TABLE IF EXISTS `info_course`;
CREATE TABLE `info_course` (
? `id` int(5) NOT NULL auto_increment,
? `no` varchar(50) NOT NULL COMMENT '課程編號',
? `name` varchar(50) NOT NULL COMMENT '課程名',
? `teacher_id` varchar(50) NOT NULL,
? `teacher_name` varchar(50) NOT NULL COMMENT '教師名',
? `selectedMan` int(11) default '0' COMMENT '已選人數(shù)',
? `capacity` int(11) default NULL COMMENT '容量',
? `time` varchar(50) default NULL COMMENT '上課時間',
? `place` varchar(50) default NULL COMMENT '上課地點',
? `credit` float default NULL COMMENT '學分',
? PRIMARY KEY? (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=gb2312;
?
-- ----------------------------
-- ----------------------------
INSERT INTO `info_course` VALUES ('2', '1', 'php', '123', '葉喜民', '0', '2', '星期一,1--2', '6521', '2');
INSERT INTO `info_course` VALUES ('3', '2', 'linux', '123', '葉喜民', '0', '2', '星期一,2--3', '6512', '3');
?
-- ----------------------------
-- Table structure for info_selected
-- ----------------------------
DROP TABLE IF EXISTS `info_selected`;
CREATE TABLE `info_selected` (
? `stu_id` varchar(50) NOT NULL,
? `course_id` int(11) NOT NULL,
? PRIMARY KEY? (`stu_id`,`course_id`)
) ENGINE=MyISAM DEFAULT CHARSET=gb2312;
?
-- ----------------------------
-- ----------------------------
?
-- ----------------------------
-- ----------------------------
DROP TABLE IF EXISTS `info_student`;
CREATE TABLE `info_student` (
? `id` varchar(50) NOT NULL COMMENT '學號',
? `name` varchar(20) NOT NULL COMMENT '姓名',
? `dept` varchar(40) NOT NULL COMMENT '系名',
? `major` varchar(40) NOT NULL COMMENT '專業(yè)',
? `sex` char(4) NOT NULL COMMENT '性別',
? `class` varchar(20) NOT NULL COMMENT '班級',
? `password` varchar(50) NOT NULL default 'e10adc3949ba59abbe56e057f20f883e' COMMENT '密碼',
? PRIMARY KEY? (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=gb2312;
?
-- ----------------------------
-- ----------------------------
INSERT INTO `info_student` VALUES ('123', '李勇', '計科系', '網(wǎng)絡(luò)', '男', '1', 'e10adc3949ba59abbe56e057f20f883e');
?
-- ----------------------------
-- ----------------------------
DROP TABLE IF EXISTS `info_teacher`;
CREATE TABLE `info_teacher` (
? `id` varchar(50) NOT NULL COMMENT '工號',
? `name` varchar(20) NOT NULL COMMENT '姓名',
? `dept` varchar(40) default NULL COMMENT '系名',
? `sex` char(4) default NULL COMMENT '性別',
? `zhicheng` varchar(30) default NULL COMMENT '職稱',
? `password` varchar(50) NOT NULL default 'e10adc3949ba59abbe56e057f20f883e' COMMENT '密碼',
? PRIMARY KEY? (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=gb2312;
?
-- ----------------------------
-- ----------------------------
INSERT INTO `info_teacher` VALUES ('123', '葉喜民', '新鄉(xiāng)', '男', '輔導老師', 'e10adc3949ba59abbe56e057f20f883e');
5 部署和運行
5.1部署環(huán)境
以windows系統(tǒng)為例,現(xiàn)在系統(tǒng)創(chuàng)建Apache+php+mysql服務環(huán)境,推薦使用套件,方面快捷!~
?
5.2 安裝文件
先將所有5.3 創(chuàng)建數(shù)據(jù)庫
創(chuàng)建一個名為test編碼為utf的數(shù)據(jù)庫 ,將目錄里database.sql文件導入test數(shù)據(jù)庫
?
5.4 測試
學生和教師入口:http://localhost/index.php/Home/index
? ? 管理員入口:http://localhost/index.php/Admin/index
? ? 管理員賬號密碼均為admin? 預設(shè)老師學生賬號均為~ 賬號:123 密碼:123456
? 測試成功運行~!
?
5.5 運行
添加學生信息,搭建正規(guī)服務器,添加dns域名,向?qū)W生和教師開放應用!
6結(jié)論
基于b/s的技術(shù)應用可使用廣泛分布的web資源輕松高效的達到預期目的(利用通用的瀏覽器,省去ui的開發(fā)),免費開源的Apache+php+mysql技術(shù)可以簡單高效的提供服務器方的支持。mvc技術(shù)使得復雜的多層結(jié)構(gòu)應用系統(tǒng)開發(fā)變得容易,亦能提高開發(fā)人員的效率,降低軟件的開發(fā)和維護成本。
?
參考文獻:
[1] (澳)威利 著,武欣 等譯. PHP和MySQL Web開發(fā).北京:機械工業(yè)出版社,2009:153~167.
[2] 高洛峰.細說PHP.北京:電子工業(yè)出版社,2009:162~234.
[3] www.php100.com
[4] www.csdn.net
[5]《thinkphp手冊簡體中文版》chm版
[6]《php手冊簡體中文版 》chm版
總結(jié)
以上是生活随笔為你收集整理的基于php的选课系统设计(含源文件)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c语言中把一个数缩小十倍_小学数学易错点
- 下一篇: python实例属性引用-python之