⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 search_book.php

📁 不错的图书管理系统。简单明了
💻 PHP
字号:
<?php
include("header.php");

function listtree($downids,$rs2)
{
	global $conn;
	if($downids=="0")
		return;
	else
	{
		$sql="select * from class where parentid=".$downids." order by classid";
		$rs=mysql_query($sql,$conn);
		if(mysql_num_rows($rs)==0)
			return;
		else
		while($lists=mysql_fetch_array($rs))
		{
			echo "<option value=\"".$lists[classid]."\">";
			for($j=1;$j<$lists[layer];$j++)
				echo "|&nbsp;";
			echo $lists[classname]."</option>";
			listtree($lists[classid]);
		}
	}
}

$conn=@mysql_connect($db_server,$db_user,$db_password);
if(! $conn)
{
	echo "<P align=center>数据库连接出错";
	exit(0);
}

$flag=@mysql_select_db($db_name,$conn);
if(! $flag)
{
	echo "<P align=center>选择数据库出错";
	exit(0);
}
if($mode==""):
?>
<p> </p>

<div align="center">
  <center>
  <table border="1" width="60%" bordercolor="#008000" cellspacing="0" cellpadding="0" height="277">
    <tr>
      <td width="100%" height="275" valign="top">
         <p align="center" class="1">书藉查询</P>
         <form action="search_book.php?mode=doit" method="post">
		 <table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td width="50%" align="right">书名:</td>
            <td width="50%"><input type="text" name="book_name" size="20"></td>
          </tr>
          <tr>
            <td width="50%" align="right">作者:</td>
            <td width="50%"><input type="text" name="member_name" size="20"></td>
          </tr>
          <tr>
            <td width="50%" align="right">出版社:</td>
            <td width="50%"><input type="text" name="publish" size="20"></td>
          </tr>
          <tr>
            <td width="50%" align="right">出版时间:</td>
            <td width="50%"><input type="text" name="outtime1" size="4">年<input type="text" name="outtime2" size="2">月</td>
          </tr>
          <tr>
            <td width="50%" align="right">分类:</td>
            <td width="50%">
              <select size="1" name="class">
<?php
$sql="select * from class where layer=1";
$rs=mysql_query($sql,$conn);
if(mysql_num_rows($rs)==0)
{
	echo "<option value=0>没有找到类</option>";
	$flag=0;
}
else
	echo "<option value=0>所有类</option>";
	for($i=1;$i<mysql_num_rows($rs);$i++)
	{
		$lists=mysql_fetch_array($rs);
		echo "<option value=\"".$lists[classid]."\">".$lists[classname]."</option>";
		listtree($lists[classid]);
	}

?>        
              </select>
            </td>
          </tr>
          <tr>
            <td width="50%" align="right">各条件:与<input type="radio" value="and" name="select1" checked>
              或<input type="radio" value="or" name="select1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> 
            <td width="50%">绝对匹配&nbsp;<input type="radio" value="yes" name="select2" checked>
              模糊匹配<input type="radio" value="no" name="select2"></td> 
          </tr> 
          <tr> 
            <td width="50%" align="center" colspan="2"><input type="submit" value="查询" name="B1"></td> 
          </tr> 
        </table> 
        </form> 
        <p align=center><font color=red size=2>请注意:输入条件中应至少有一项不为空</font></p>
      </td> 
    </tr> 
  </table> 
  </center> 
</div> 
<?php
endif;
function selects($strname,$strname2,$selectkey,$selectname)
{
	global $sql;
	if($selectname=="" || $selectname==" ")
		;
	else
		if(strpos($sql,"=") || strpos($sql,"like"))
			if($selectkey=="yes")
				return " ".$strname2." ".$strname."='".$selectname."'";
			else
				return " ".$strname2." ".$strname." like '%".$selectname."%'";
		else
			if($selectkey=="yes")
				return $strname."='".$selectname."'";
			else
				return $strname." like '%".$selectname."%'";
	
}
if($mode=="doit")
{
	$postword="search_book.php?mode=doit&book_name=".$book_name."&member_name=".$member_name;
	$postword.="&publish=".$publish."&outtime1=".$outtime1."&outtime2=".$outtime2."&select1=".$select1."&select2=".$select2;
	if($pager=="")
		$pagenum=0;
	else
		$pagenum=$pager;
	$pagenum=(int)$pagenum;
	$sql="select * from book where (".selects("book_name",$select1,$select2,$book_name);
	$sql.=selects("book_member",$select1,$select2,$member_name);
	$sql.=selects("book_publish",$select1,$select2,$publish);
	//echo $outtime1." or ".$outtime2."<br>";
	if(trim($outtime1)=="")
		$outtimes="";
	else
	{
		
		if(trim($outtime2)=="")
			$temptime="01";
		else
			$temptime=$outtime2;
		echo $temptime."01".$outtime1;
		if(checkdate($temptime,"01",$outtime1))
		{
			echo $outtimes."lksdf";
			$outtimes=$outtime1."-".$temptime."-01";
		}
		else
			$outtimes="";
		
	}
	
	$sql.=selects("book_outtime",$select1,$select2,$outtimes);
	if($class=="" or $class=="0")
		;
	else
		$sql.=" ".$select1." book_sorter=".$class;
	$oldsql=$sql.")";
	$sql.=") order by book_outtime desc";
	$sql.=" limit ".($pagenum*$pagelenth).",".(($pagenum+1)*$pagelenth);
	//echo $sql;
	$rs=@mysql_query($sql,$conn) or die ("<P align=center>查询发生错误<br><a href=\"javascript:history.go(-1)\">返回</a>");
	if(mysql_num_rows($rs)==0)
		echo "<P align=center>数据库中没有符合要求的记录<br><a href=\"javascript:history.go(-1)\">返回</a>";
	else
		list_sequel($rs,$postword,$oldsql);

}
mysql_close($conn);
function list_sequel($rs,$postword,$oldsql)
{
	global $conn,$pagelenth,$pagenum;
?>
<div align="center">
  <center>
  <table border="1" width="90%" bordercolor="#008000" cellspacing="0" cellpadding="0" height="205">
    <tr>
      <td width="100%" height="203" valign="top">
        <p align="center" class="1">查询结果</p>
        <table border="1" width="100%" cellspacing="0" cellpadding="0" bordercolor="#FFCCCC">
          <tr>
            <td width="20%" align="center" height="21">书名</td>
            <td width="10%" align="center">作者</td>
            <td width="20%" align="center">出版社</td>
            <td width="10%" align="center">出版日期</td>
            <td width="24%" align="center">书籍编号</td>
             <td width="8%" align="center">总库存</td>
            <td width="8%" align="center">现存</td>

          </tr>
<?php
		while($lists=mysql_fetch_array($rs))
		{
		  echo "<tr><td width=\"20%\" height=\"21\">";
		  echo $lists[book_name];
		  echo "</td>";
		  
		  echo "<td width=\"10%\">";
		  echo $lists[book_member];
		  echo "</td>";
		  
		  echo "<td width=\"20%\">";
		  echo $lists[book_publish];
		  echo "</td>";
		  
		  echo "<td width=\"10%\">";
		  echo substr($lists[book_outtime],0,7);
		  echo "</td>";
		  
		  echo "<td width=\"24%\">";
		  echo $lists[book_no];
		  echo "</td>";
		  
		  echo "<td width=\"8%\">";
		  echo $lists[book_number];
		  echo "</td>";
		  
		  echo "<td width=\"8%\">";
		  echo $lists[book_sotcks];
		  echo "</td>";
		  
		  echo "</tr>";
		}
        echo "</table>";
        
        $rs1=mysql_query($oldsql,$conn);
        $maxnum=mysql_num_rows($rs1);
        //echo $maxnum;
        //echo "<br>".$pagelenth;
        if($maxnum >= $pagelenth)
        	$maxpagenum= $maxnum / $pagelenth;
        if(($maxnum % $pagelenth)!=0)
        	$maxpagenum+=1;
        echo "<P >";
        $j=0;
        for($i=0;$i<$maxpagenum;$i++)
        {
        	if($pagenum!=$i)	
        		echo "【<a href=\"".$postword."&pager=".$i."\">".($i+1)."</a>】";
        	else
        		echo "【".($i+1)."】";
        	if((($j+1) % 15)==0)
        		echo "<br>";
        	$j+=1;
        }
  echo "</center>";
  echo "<p align=\"right\" >【".($pagenum+1)."/".$maxpagenum."】";
?>
      </td>
    </tr>
  </table>
</div>
<?php
}
?>
<p align=center><a href="default.htm">返回首页</a></p>
</body> 
 
</html> 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -