嗨朋友我要去分页我的book_search.php,它显示按标题名称或作者姓名或出版商名称搜索的图书的结果。但是for si = ome搜索结果太长了,所以我需要用下一个和前一个按钮对这个结果进行分页。我有代码,但是你可以让我知道我需要更改代码以便使用下一个和上一个按钮。
先谢谢你。
代码如下
book_search.php
<?php
include('assets/page_header.php');
?>
<div class="container">
<h1>SEARCHING THE BOOK</h1>
<form id="search" name="search" action="#" method="post">
Search : <input type="text" name="author" id="author">
<input id="submit" name="submit" type="submit" value="Submit">
</form>
<div id="display"></div>
</div>
db/ajax.php
<?php
include('db.php');
$page="";
if(isset($_GET['page']))
{
$page=$_GET['page'];
}
$num_rec_per_page = 5;
?>
<div id="navigation">
<?php
if(isset($_POST['author']))
{
$author=mysql_real_escape_string($_POST['author']);
if($author=="")
{
echo "Please Enter Title or Author or Publisher";
}
else
{
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * $num_rec_per_page;
$query1="select * from books where title LIKE '%$author%' OR author LIKE '%$author%' OR publisher LIKE '%$author%' LIMIT $start_from, $num_rec_per_page ";
$rs_result=mysql_query("select * from books where title LIKE '%$author%' OR author LIKE '%$author%' OR publisher LIKE '%$author%'");
$total_records = mysql_num_rows($rs_result); //count number of records
$total_pages = ceil($total_records / $num_rec_per_page);
//$phpself=$_SERVER['PHP_SELF'];
if($page>1)
{
$pagenumber=$page-1;
$prev="<a href=\"book_search.php?page=$pagenumber\">[Back]</a>";
$first="<a href=\"book_search.php?page=1\">[FirstPage]</a>";
}
else
{
$prev='';
$first='';
}
if($page<$total_pages)
{
$pagenumber=$page+1;
$next="<a href=\"book_search.php.?page=$pagenumber\">[Next]</a>";
$last="<a href=\"book_search.php.?page=$total_pages\">[LastPage]</a>";
}
else
{
$next="";
$last="";
/*$next='[next]';
$last='[LastPage]';*/
}
echo $first.$prev."Showing page<bold>$page</bold>of<bold>$total_pages</bold>pages".$next.$last;
$result1=mysql_query($query1);
//print_r($result1);
$count=mysql_num_rows($result1);
//echo $count;
$display= "<table align='center'>";
$display.= "<tr><td>title</td> <td>author</td> <td>publisher</td> <td>numcopies</td> <td>status</td> <td>number_of_copies_available</td> <td>Action</td> </tr>";
while($row=mysql_fetch_array($result1)){
$count=mysql_num_rows($result1);
//print_r($row['bookid']);
$r12=$row['bookid'];
$query2=mysql_query("select bookid from bookrentalinfo where bookid=$r12");
$num_copies_borrowed=mysql_num_rows($query2);
$num_copies_count=$row['numcopies'];
$number_of_copies_available=$num_copies_count-$num_copies_borrowed;
$display.= "<tr>";
//echo "<td>".$row['bookid']."</td>";
$display.="<td>".$row['title']."</td>";
$display.= "<td>".$row['author']."</td>";
$display.= "<td>".$row['publisher']."</td>";
$display.= "<td>".$row['numcopies']."</td>";
$display.= "<td>".$row['status']."</td>";
$display.= "<td>".$number_of_copies_available."</td>";
if($number_of_copies_available>0)
{
$display.= "<td><a href='borrow_search.php?book_id=".$row['bookid']."'>Rent</a></td>";
}
else {
$display.= "rent link is not activated";
$display.="<td></td>";
}
$display.= "</tr>";
}
$display.="</table>";
echo $display;
}
}
?>
</div>
</html>
script.js
$(document).ready(function(){
$( "#renewaldate" ).datepicker({ minDate: 0});
$("#submit").click(function(e){
//console.log("div value"+$('#display').html());
var author = $("#author").val();
/*var email = $("#email").val();
var password = $("#password").val();
var contact = $("#contact").val();*/
// Returns successful data submission message when the entered information is stored in database.
//var dataString = 'name1='+ name + '&email1='+ email + '&password1='+ password + '&contact1='+ contact;
var dataString='author='+author;
//var dataString = $(this).serializeArray();
if(author=='')
{
alert("Please Enter Author or Title or Publisher Fields");
}
else
{
// AJAX Code To Submit Form.
$.ajax({
type: "POST",
url: "db/ajax.php",
data: dataString,
cache: false,
success: function(result){
//alert("submitted"+result);
$('#display').html(result);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
}
e.preventDefault();
});
});