Jump to content

Regarding paging in search


new_to_php

Recommended Posts

Hi ,

I am implementing search functionality for a

small set of files.

In below code: $keyword_array refers to a search string.

I am searching for a word in a file and printing on screen.All results are displayed

in a single page. Here I want to use paging , splitting results in different pages.

how it can be done ?

 

one solution could be: I will store all results in an array , make array as session variable and use paging.

problem with above is:

  1. In below code , I am displaying results as soon as I found in any file. But with above approch

I have to wait till all results are stored in an array.

  2. Paging with browser TABS is failing. Because two tabs in a browser uses same session. So the session variable in one TAB will be overwritten by the sassion variable in another TAB.

How to over come above problems ?

 

function CheckFiles($dir) { 
  $handle=opendir($dir);
  while(false!==($file=readdir($handle)))
  {
      if(is_dir("$dir/$file"))
      {
        CheckFiles("$dir/$file");
      }
      else
      {  
          $data=fread(fopen("$dir/$file","r"),filesize("$dir/$file"));
          $data=strip_tags($data);
          foreach($keyword_array as $value1) {
            if(eregi($value1,$data))
            { 
              $url ="$dir/$file";
              echo("<a href=$url > $url</a>");
              echo("<br>");
              break;
            }
          }
        }
      }

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.