<meta charset="gb2312">
<?
include ('Adminloginok.html');
require ('dbconnect.php');
// 查询书不需要登录
?>
<?
// 获得参数
$id=$_POST['id'];
$title=$_POST['title'];
$author=$_POST['author'];
$publisher=$_POST['publisher'];
$year=$_POST['year'];
function Get_search_id(){
$args=func_get_args();
$queryfield=$args[0];
$queryvalue=$args[1];
$conn=$args[2];
$id_search=array(); //store the searched id
$sqlsearch="select id from tb_book where ".$queryfield." like '%".$queryvalue."%'";
//print $sqlsearch;
$re_search=mysql_query($sqlsearch,$conn);
while ($row_search=mysql_fetch_row($re_search)){
array_push($id_search,$row_search[0]);
}
return $id_search;
}
$resultid=array();
$arr=array();
// 定义变量控制是否已有查询结果
$flag=0;
if ($id!=""){
$id_id=array();
$result=mysql_query("select id from tb_book where id='$id'",$conn);
while($row=mysql_fetch_row($result)){
array_push($id_id,$row[0]);
}
$flag=1;
$resultid=$id_id;
}
if ($title!=""){
$title_id=array();
$title_id=Get_search_id("title",$title,$conn);
// 前面没有查询结果
if ($flag==0){
$resultid=$title_id;
}
// 已有查询结果
else {
$flag=1;
// 取交集
$arr=array_intersect($resultid,$title_id);
$resultid=$arr;
}
}
if ($author!=""){
$author_id=array();
$author_id=Get_search_id("author",$author,$conn);
// 前面没有查询结果
if ($flag==0){
$resultid=$author_id;
}
// 已有查询结果
else {
$flag=1;
// 取交集
$arr=array_intersect($resultid,$author_id);
$resultid=$arr;
}
}
if ($publisher!=""){
$publisher_id=array();
$publisher_id=Get_search_id("publisher",$publisher,$conn);
// 前面没有查询结果
if ($flag==0){
$resultid=$publisher_id;
}
// 已有查询结果
else {
$flag=1;
// 取交集
$arr=array_intersect($resultid,$publisher_id);
$resultid=$arr;
}
}
if ($year!=""){
$year_id=array();
$result=mysql_query("select id from tb_book where publish_year='$year'",$conn);
while($row=mysql_fetch_row($result)){
array_push($year_id,$row[0]);
}
// 前面没有查询结果
if ($flag==0){
$resultid=$year_id;
}
// 已有查询结果
else {
$flag=1;
// 取交集
$arr=array_intersect($resultid,$year_id);
$resultid=$arr;
}
}
// 显示查询结果
$num=count($resultid);
if ($num==0){
echo "<div align=center><font color=red>没有找到符合查询条件的图书</a></div>";
exit();
}
// 获得查询到的书的详细信息
for ($i=0;$i<$num;$i++){
$bresult=mysql_query("select * from tb_book where id='$resultid[$i]'",$conn);
$binfo=mysql_fetch_array($bresult);
}
?>
<form name="form1" method="post" action="<?php echo $PHP_SELF ?>">
<table width="60%" border="0" cellspacing="1" cellpadding="3" align="center">
<tr>
<th colspan="2">借 书 登 记</th>
</tr>
<tr>
<td width="30%" height="32" align="right">图书编号:</td>
<td width="70%" height="32"><?echo $id?>
<? // 传递图书ID信息 ?>
<input type="hidden" name="id" value="<? echo $bookinfo[id];?>">
<input type="hidden" name="title" value="<? echo $bookinfo[title];?>">
<input type="hidden" name="leave" value="<? echo $bookinfo[leave_number];?>">
</td>
</tr>
<tr>
<td width="30%" align="right">书名:</td>
<td width="70%"><? echo "$binfo[title]";?></td>
</tr>
<tr>
<td width="30%" align="right">作者:</td>
<td width="70%"><? echo "$binfo[author]";?></td>
</tr>
<tr>
<td width="30%" align="right">出版社:</td>
<td width="70%"><? echo "$binfo[publisher]";?></td>
</tr>
<tr>
<td width="30%" align="right">出版年份:</td>
<td width="70%"><? echo "$binfo[publish_year]";?></td>
</tr>
<tr>
<td height="23" align="right">总共:<? echo "$binfo[total]";?>本;</td>
<td height="23">库存剩余:<? echo "$binfo[leave_number]";?>本</td>
</tr>
</table>
</form>
<form name="form1" method="post" action="borrow_result.php" >
<table width="60%" border="0" cellspacing="1" cellpadding="3" align="center">
<tr>
<td width="30%" align="right">借阅用户ID:</td>
<td width="70%">
<input type="text" name="user_id" size="10">
</td>
</tr>
<tr>
<td width="30%" align="right">
<input type="submit" name="lend" value="借出">
</td>
<td width="70%">
<input type="reset" name="Submit2" value="重置">
</td>
</tr>
</table>
</form>
</body>
</html>