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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.