<?php
echo "<div id='main'>";
echo "<div class='hr'><hr /></div>";
echo "<div id='example'>";
// 建立数据库连接
require "conn.php";
//判断是否是翻页时传递过来的参数
if(isset($_GET['bookid']))
{
$tbookid = $_GET['bookid'];
}
else
{
$tbookid = $_POST['bookid'];
}
if(isset($_GET['bookname']))
{
$tbookname = $_GET['bookname'];
}
else
{
$tbookname = $_POST['bookname'];
}
if(isset($_GET['bookauthor']))
{
$tbookauthor = $_GET['bookauthor'];
}
else
{
$tbookauthor = $_POST['bookauthor'];
}
if(isset($_GET['publish']))
{
$tpublish = $_GET['publish'];
}
else
{
$tpublish = $_POST['publish'];
}
global $sql1;
global $sql2;
//根据条件设计查询语句
$sql1 = "SELECT count(*) FROM $book WHERE ";
$sql2 = "select * from $book WHERE ";
if($tbookid != "")
{
$sql1 = $sql1." bookid = '$tbookid'";
$sql2 = $sql2." bookid = '$tbookid'";
}
if(($tbookname != "") && ($tbookid != ""))
{
$sql1 = $sql1." and bookname = '$tbookname '";
$sql2 = $sql2." and bookname = '$tbookname '";
}
elseif (($tbookname != "") && ($tbookid == ""))
{
$sql1 = $sql1." bookname = '$tbookname '";
$sql2 = $sql2." bookname = '$tbookname '";
}
if(($tbookauthor != "") && (($tbookid != "") || ($tbookname != "")))
{
$sql1 = $sql1." and author = '$tbookauthor '";
$sql2 = $sql2." and author = '$tbookauthor '";
}
elseif ($tbookauthor != "")
{
$sql1 = $sql1." author = '$tbookauthor '";
$sql2 = $sql2." author = '$tbookauthor '";
}
if(($tpublish != "") && (($tbookid != "") || ($tbookname != "") || ($tbookauthor != "")))
{
$sql1 = $sql1." and publish = '$tpublish '";
$sql2 = $sql2." and publish = '$tpublish '";
}
elseif ($tpublish != "")
{
$sql1 = $sql1." publish = '$tpublish '";
$sql2 = $sql2." publish = '$tpublish '";
}
// 获取当前页数
if( isset($_GET['page']) )
{
$page = intval( $_GET['page'] );
}
else
{
$page = 1;
}
// 每页数量
$page_size = $psize;
// 获取总数据量
$result = mysql_query($sql1);
$row = mysql_fetch_row($result);
$amount = $row[0];
//echo $amount;
// 记算总共有多少页
if($amount)
{
if( $amount < $page_size )
{
//如果总数据量小于$pagesize,那么只有一页
$page_count = 1;
}
//取总数据量除以每页数的余数
if( $amount % $page_size )
{
//如果有余数,则页数等于总数据量除以每页数的结果取整再加一
$page_count = (int)($amount / $page_size) + 1;
}
else
{
//如果没有余数,则页数等于总数据量除以每页数的结果
$page_count = $amount / $page_size;
}
}
else
{
$page_count = 0;
}
echo "<h2>所 有 图 书</h2>";
echo "<blockquote>";
echo "<p>管理员可以查查看、修改及删除下述图书记录:</p>";
echo "</blockquote>";
echo "<fieldset>";
echo "<ul>";
echo "<li>";
echo "<label for='lbookid'>图书编号-></label>";
echo "<label for='lbookid'>图书名称-></label>";
echo "<label for='lbookid'>图书作者-></label>";
echo "<label for='lbookid'>出版社-></label>";
echo "<label for='lbookid'>出版日期-></label>";
echo "<label for='lbookid'>图书单价-></label>";
echo "<label for='lbookid'>图书数量-></label>";
echo "<label for='lbookid'>当前状态-></label>";
echo "<label for='lbookid'>图书简介</label>";
echo "</li>";
echo "</ul>";
echo "<ol>";
// 获取数据,以二维数组格式返回结果
if( $amount )
{
$sql2 = $sql2." order by id desc limit ". ($page-1)*$page_size .", $page_size";
$result = mysql_query($sql2);
$num = mysql_num_rows($result);
//echo $num;
for ($i=0;$i<$num;$i++)
{
$row = mysql_fetch_array($result);
$id = $row['id'];
$bookid = $row['bookid'];
$bookname = $row['bookname'];
$author = $row['author'];
$publish = $row['publish'];
$pdate = $row['pdate'];
$price = $row['price'];
$amount = $row['amount'];
$state = $row['state'];
$memo = $row['memo'];
echo "<li>";
echo "<label for='lbookid'>".$bookid."-></label>";
echo "<label for='lbookid'>".$bookname."-></label>";
echo "<label for='lbookid'>".$author."-></label>";
echo "<label for='lbookid'>".$publish."-></label>";
echo "<label for='lbookid'>".$pdate."-></label>";
echo "<label for='lbookid'>".$price."-></label>";
echo "<label for='lbookid'>".$amount."-></label>";
echo "<label for='lbookid'>".$state."-></label>";
echo "<marquee direction='left'>";
echo "<label for='lbookid'>".$memo."</label>";
echo "</marquee>";
echo "</li>";
}
}
else
{
echo "没有记录";
}
echo "</ol>";
echo "</fieldset>";
// 翻页链接
$cx = 'bookid='.$tbookid.'&&bookname='.$tbookname.'&&bookauthor='.$tbookauthor.'&&publish='.$tpublish;
$page_string = '';
if( $page == 1 )
{
$page_string .= '第一页|上一页|';
}
else
{
// echo $cx;
$page_string .= '<a href=?'.$cx.'&&page=1>第一页</a>|
<a href=?'.$cx.'&&page='.($page-1).'>上一页</a>|';
}
if( ($page == $page_count) || ($page_count == 0) )
{
$page_string .= '下一页|尾页';
}
else
{
$page_string .= '<a href=?'.$cx.'&&page='.($page+1).'>下一页</a>|
<a href=?'.$cx.'&&page='.$page_count.'>尾页</a>';
}
echo "<br>".$page_string;
echo "</div>";
echo "</div>";
echo "<div id='extra'></div>";
echo "</div>";
?>