我有一个搜索栏,用户可以搜索。所以当他们搜索时,他们会转到搜索页面,这将显示结果取决于他们搜索的内容,并且每页最多显示五个结果,所以如果有更多结果然后将显示分页链接。
但我的代码无效,请告诉我我的错误
这是我的 search.php代码
<?php
include('include_Connection.php');
if(isset($_GET["q"]))
$q = $_GET['q'];
$q=mysql_real_escape_string($_GET['q']);
$res = mysql_query("SELECT COUNT(*) FROM scripts") or die($res."<br/><br/>".mysql_error());
$get_total_rows = mysql_fetch_array($res) ; //total records
//break total records into pages
$pags = ceil($get_total_rows[0]/$item_per_page);
//create pagination
if($pags > 1)
{
$pagination = '';
$pagination .= '<ul class="pagination pagination-sm">';
for($i = 1; $i<$pags; $i++)
{
$pagination .= '<li><a href="#" class="paginate_click" id="'.$i.'-page">'.$i.'</a></li>';
}
$pagination .= '</ul>';
}
?>
<script type="text/javascript">
$(document).ready(function() {
$("#results").load("searchq.php", {'page':0}, function() {$("#1-page").addClass('active');}); //initial page number to load
$(".paginate_click").click(function (e) {
$("#results").prepend('<div class="loading-indication"><img src="ajax-loader.gif" /> Loading...</div>');
var clicked_id = $(this).attr("id").split("-");
var page_num = parseInt(clicked_id[0]);
$('.paginate_click').removeClass('active');
$("#results").load("searchq.php", {'page':(page_num-1)}, function(){
});
$(this).addClass('active');
return false;
});
});
</script>
这是我的 searchq.php代码
<?php
include('include_Connection.php'); //include config file
//sanitize post value
$page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);
//validate page number is really numaric
if(!is_numeric($page_number)){die('Invalid page number!');}
//get current starting point of records
$position = ($page_number * $item_per_page);
//Limit our results within a specified range.
$results = mysql_query("select Name_s,Price,Full_description,Img,ID_s,Pro_Status from scripts where Pro_Status = 'Active' order by ID_s LIMIT $position, $item_per_page");
//output results from database
echo '<ul class="page_result">';
while($row = mysql_fetch_array($results,MYSQL_ASSOC))
{
echo '<li id="item_'.$row["ID_s"].'">'.$row["ID_s"].'</li>';
}
echo '</ul>';
?>