:?: some problems of displaying search results in multipage
Posted: Mon Dec 06, 2004 4:34 am
Hi, everybody
I am tring to build a search function with PHP and keyword matching(without mysql ) for my homepage. The search function has already worked. however, the search results are just displayed in one page. So I want to change it to represent in multipage. for example 5 results pre page. 12 results will be arranged in 3 pages.
But now I met a big problem. It shows nothing if I click the second or third page. I am not sure if the code is incorrect. Any help and suggestions are welcome. Thanks in advance.
... // search process
I am tring to build a search function with PHP and keyword matching(without mysql ) for my homepage. The search function has already worked. however, the search results are just displayed in one page. So I want to change it to represent in multipage. for example 5 results pre page. 12 results will be arranged in 3 pages.
But now I met a big problem. It shows nothing if I click the second or third page. I am not sure if the code is incorrect. Any help and suggestions are welcome. Thanks in advance.
Code: Select all
$found = "0";
$file_type = ".html";
$directory = opendir('.');
$limit = 5;
$page = $_REQUESTї'page'];
$query = $_POSTї'query'];
if (!isset($_GETї'page'])) {
$page = 1;
}
if($page > 1){
$query = $_REQUESTї'query'];
}
if(strlen($search) < 3){
echo "Please enter more characters in this field.";
exit();
}Code: Select all
if($found != "0"){
echo "$found Results found for " $search "<p>";
$arr = explode("\n", $arr);
natsort($arr);
reset($arr);
$arr = array_reverse($arr);
// create multipages for Search Results
$num_rows = sizeof($arr);
$sOut = "<center><p> - ";
$num_pages = ceil($num_rows / $limit);
$first = ($page-1) * $limit;
$last = $first + $limit;
// output the results saved in Array
for($i=$first; $i<$last; $i++) {
$output .= $arrї$i]."\n";
}
print $output;
for($x=1;$x<=$num_pages;$x++){
$pos_page = ($x - 1) * $limit;
if($pos_page != $page){
$sOut .= "<a href="$PHP_SELF?query=$query&page=".($pos_page + 1)."">$x</a> - ";
}
else{
$act_page = $x;
$sOut .= "<font style="font-weight: bold">$x</font> - ";
}
}
$sOut .= "<br /><b>Page $act_page from $num_pages pages</b><br />";
$sOut .= "</p></center>";
echo $sOut;
}