如何做写一套图书馆管理系统(三)借阅管理

来源:互联网 发布:2016年全球云计算市场 编辑:程序博客网 时间:2024/05/02 22:57

接下来,是书本与读者之间借阅关系的管理。

第一步仍然是确定数据表。

这是追求理想型问题,我们从目的定位出发。

管理借阅记录的目的是记录每一本图书的借阅状态,防止图书丢失。

所以,我们的字段分为三种类型,第一种类型能准确定位到被借的图书,第二种准确定位到借书的人,第三种能准确定位到借书这件事情。

那么最基本的三个字段即可:书的条形码、读者编号、借书时间。

再给一个id用于记录借阅记录数。

所以数据表结构为:

idbarcodereadernumborrowtimeint(10)int(100)int(100)datetime()

create table borrows(id int(10) auto_increment primary key,barcode int(10) not null,readernum int(10) not null,borrowtime datetime);

下一步是借阅的主页:

borrows.php

<html><span style="white-space:pre"></span><head><span style="white-space:pre"></span><title>借阅档案管理</title><span style="white-space:pre"></span></head><span style="white-space:pre"></span><body><span style="white-space:pre"></span><form method = "POST" action = ""><span style="white-space:pre"></span><select name = "searchtype"><span style="white-space:pre"></span><option value = "readernumber">读者编号</option><span style="white-space:pre"></span><option value = "paperstype">图书条形码</option><span style="white-space:pre"></span><option value = "all">全部</option><span style="white-space:pre"></span></select><span style="white-space:pre"></span><input name = "key" type = "text"></input><span style="white-space:pre"></span><button type = "submit">提交</button><span style="white-space:pre"></span><a href = "borrows_add.php">借书</a><span style="white-space:pre"></span><a href = "borrows_return.php">还书</a><span style="white-space:pre"></span></form><span style="white-space:pre"></span><table><span style="white-space:pre"></span><tr><span style="white-space:pre"></span><th>书名</th><span style="white-space:pre"></span><th>条形码</th><span style="white-space:pre"></span><th>读者姓名</th><span style="white-space:pre"></span><th>读者编号</th><span style="white-space:pre"></span><th>借书时间</th><span style="white-space:pre"></span><th>是否归还</th><span style="white-space:pre"></span></tr><span style="white-space:pre"></span><?php<span style="white-space:pre"></span>include "conn/conn.php";<span style="white-space:pre"></span>/*只知道一个表的主键,怎么通过这个主键去寻找并填充其他主键?<span style="white-space:pre"></span>方法之一是,先把这个主键<span style="white-space:pre"></span>*/<span style="white-space:pre"></span>@$f = $_POST['searchtype'];<span style="white-space:pre"></span>@$key = $_POST['key'];<span style="white-space:pre"></span>$sql = mysql_query("select * from borrows;");<span style="white-space:pre"></span>$info = mysql_fetch_array($sql);<span style="white-space:pre"></span>if($info == false)<span style="white-space:pre"></span>echo "No Records!";<span style="white-space:pre"></span>else if($info == true){<span style="white-space:pre"></span>if($key == ""||$f=="all"){<span style="white-space:pre"></span>do{<span style="white-space:pre"></span>?><span style="white-space:pre"></span><tr><span style="white-space:pre"></span><td><?php echo $info['bookname'];?></td><span style="white-space:pre"></span><td><?php echo $info['barcode'];?></td><span style="white-space:pre"></span><td><?php echo $info['readername'];?></td><span style="white-space:pre"></span><td><?php echo $info['readernum'];?></td><span style="white-space:pre"></span><td><?php echo $info['borrowtime'];?></td><span style="white-space:pre"></span><td><?php if($info['if_return']) echo "已归还";else{echo "未归还";}?></td><span style="white-space:pre"></span><?php<span style="white-space:pre"></span>}while($info = mysql_fetch_array($sql)); <span style="white-space:pre"></span>}else{<span style="white-space:pre"></span>$sql = mysql_query("select * from borrows where $f like '%$key%';"); //记住,列名是不需要加引号的。<span style="white-space:pre"></span>$info = mysql_fetch_array($sql);<span style="white-space:pre"></span>if($info == false)<span style="white-space:pre"></span>echo "No such records were found!";<span style="white-space:pre"></span>else{<span style="white-space:pre"></span>do{<span style="white-space:pre"></span>?><span style="white-space:pre"></span><tr><span style="white-space:pre"></span><td><?php echo $info['bookname'];?></td><span style="white-space:pre"></span><td><?php echo $info['barcode'];?></td><span style="white-space:pre"></span><td><?php echo $info['readername'];?></td><span style="white-space:pre"></span><td><?php echo $info['readernum'];?></td><span style="white-space:pre"></span><td><?php echo $info['borrowtime'];?></td><span style="white-space:pre"></span><td><?php echo $info['if_return'];?></td><span style="white-space:pre"></span><?php<span style="white-space:pre"></span><span style="white-space:pre"></span>}while($info = mysql_fetch_array($sql));<span style="white-space:pre"></span>}<span style="white-space:pre"></span>}<span style="white-space:pre"></span>}<span style="white-space:pre"></span>?><span style="white-space:pre"></span></table><span style="white-space:pre"></span></body></html>

2.增加借书记录的页面,borrows_add.php

<html><head><title>添加借书信息</title></head><body><form action = "borrows_add_ok.php" method = "POST"><label>被借书目条形码</label><input type = "text" name = "barcode"></input></br><label>借书读者编号</label><input type = "text" name = "readernumber"></input></br><button type = "submit" >提交</button><input name="Submit2" type="button" value="返回" onClick="history.back();"></body></html>
3.borrows_add_ok.php

<?phpinclude "conn/conn.php";$barcode = $_POST['barcode'];$readernumber = $_POST['readernumber'];$sql = mysql_query("select * from books where barcode = '$barcode'");$info = mysql_fetch_array($sql);$bookname = $info['bookname'];$sql = mysql_query("select * from readers where readernumber = '$readernumber'");$info = mysql_fetch_array($sql);$readername = $info['readername'];$borrowtime = date("Y-m-d h:i:m");mysql_query("insert into borrows (barcode,bookname,readernum,readername,borrowtime)values('$barcode','$bookname','$readernumber','$readername','$borrowtime')");echo "<script language='javascript'>alert('图书信息添加成功!');history.back();</script>";?>
以上,完成了借阅记录的添加和查询。

这里我认为借阅记录还是不能被删除和修改的。

4.borrows_return.php

<html><head><title>还书</title></head><body><form action = "borrows_return_ok.php" method = "POST"><label>书目条形码</label><input type = "text" name = "barcode"></input></br><button type = "submit" >归还</button><input name="Submit2" type="button" value="放弃" onClick="history.back();"></body></html>
5.borrows_return_ok.php

<?phpinclude "conn/conn.php";$barcode = $_POST['barcode'];mysql_query("update borrows set if_return = 1 where barcode = '$barcode'");echo "<script language='javascript'>alert('还书成功!');history.back();</script>";?>





0 0
原创粉丝点击