Jump to content

Displaying search results in pages


new_to_php

Recommended Posts

 

Hi ,

I am implementing search functionality in a website. ( internal search).

In that I am taking a keyword as input and searching all the pages and storing

results in an array. I want to display 10 results per page. I wrote below logic for that.

result_array: stores all results.


session_start();
session_register("result_array"); 

//Some code to search for keyword and store results in result array.

function display_result(){
global $result_array,$page;
$file_count=1;
$result_count=count($result_array);
$page_count=$result_count/10 + 1;
echo "Total $result_count results found in $page_count pages <br>";
$start=$page*10-9;
if($result_count<$page*10){
  $end=$result_count;
} else {
  $end=$page*10;
}
   for($x=$start;$x<=$end;$x++){ 
$title = $result_array[$x][0];
$url = $result_array[$x][1];
$des = $result_array[$x][2];
             echo "$file_count.<a href=$url >$title</a>";
             echo "<br>";
             echo "$des<br>";
             $file_count++;
     }
  echo " \t\t <br>                     Result Page: ";
  for($i=1;$i<$page_count;$i++) {
  echo " <a href=\"$PHP_SELF?page=$i\">$i</a> ";
  }

 

1. Here when I click the Page 2 or 3 in result , all result contents are coming correctly.

  But format is not proper,as it is in first page.Font is also changes in other pages.

  why alignment of result is changed like that.

2. When I click any page (2 or 3) total PHP page is getting executed again , I want only the

display_result() to be executed , how it can be done ?

 

Thank you

 

Link to comment
https://forums.phpfreaks.com/topic/57045-displaying-search-results-in-pages/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.