Loading ...
Sorry, an error occurred while loading the content.
 

Re: [PBML] Filtering results in a text database

Expand Messages
  • Nathan.Jeffrey@dhs.vic.gov.au
    Sorry, I m not going to give you a full answer (no time at present :-), but most other places do it with positioning data in URLs. So you could have a $pos,
    Message 1 of 9 , Sep 29, 2002
      Sorry, I'm not going to give you a full answer (no time at present :-),
      but most other places do it with positioning data in URLs. So you could
      have a $pos, that points to the number of records displayed so far, or
      something like that.

      For example...
      http://www.google.com/search?q=test&hl=en&lr=&ie=UTF-8&start=10&sa=N
      has a 'start' variable that says start printing after 10 results.

      Hope it helps!

      N





      "Don Smith" <dmsmith@...>
      29/09/2002 07:41 AM
      Please respond to perl-beginner


      To: <perl-beginner@yahoogroups.com>
      cc:
      Subject: [PBML] Filtering results in a text database


      Greetings again folks,

      I have a situation where I'm working with a potentially large text
      database
      (I'm not sure how large it will get and my plan is to, eventually, use
      MySql, but for now, I'm stuck with a pipe delimited text file).

      I need to filter the results and return (we'll say for now) 5 records per
      screen. I've been playing with this quite a while and haven't been able
      to
      figure it out. I know search engines do it and I've looked at code from a
      number of scripts, but, frankly, they lose me.

      The code below returns all the results in the database. My sample database
      file is included below the code. Put both in the same directory and the
      script should run as-is.

      Any help you folks can give me would be much appreciated.

      Thanks,

      Don


      ########### Start - Script #############

      #!/usr/bin/perl -w

      use lib '/CGI.pm';
      use CGI qw/:standard/;
      use CGI::Carp 'fatalsToBrowser';

      use strict;

      my $foo=new CGI;


      my $database= 'Test_DB.txt';

      #################
      # Neither of these two variables are currently used in this
      # script. I include them so you can see what I want to be
      # able to do.

      my $filter = "category1"; # Category to filter by. Show
      # only these reults.

      my $maxNum = "5"; # maximum number of records
      # to display per page.
      #################

      open (ORGDB,"<$database");
      my @ODB=<ORGDB>;
      close (ORGDB);

      print "Content-type: text/html\n\n";
      print "<html><body><br><h2>Test View Output</h2><Center><table
      width=50% border= 1><tr><th>Category</th><th>Line</th></tr>";
      foreach my $rec (@ODB){
      chomp($rec);
      (my $category,my $line)=split(/\|/,$rec);
      print"<tr><td>$category</td><td>$line</td></tr>\n";
      }
      print "</table></Center></body></html>\n";


      ########### End - script ###########

      #### Test_DB.txt #####

      category1 | line 1
      category2 | line 2
      category3 | line 3
      category1 | line 4
      category2 | line 5
      category3 | line 6
      category1 | line 7
      category2 | line 8
      category3 | line 9
      category1 | line A
      category2 | line B
      category3 | line C
      category1 | line D
      category2 | line E
      category3 | line F
      category1 | line G
      category2 | line H
      category3 | line I

      #### End Test_DB.txt ######



      ---
      Outgoing mail is certified Virus Free.
      Checked by AVG anti-virus system (http://www.grisoft.com).
      Version: 6.0.391 / Virus Database: 222 - Release Date: 9/19/02



      Unsubscribing info is here:
      http://help.yahoo.com/help/us/groups/groups-32.html

      Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/







      _________________________________________________________________________________

      This email contains confidential information intended only for the person named above and may be subject to legal privilege. If you are not the intended recipient, any disclosure, copying or use of this information is prohibited. The Department provides no guarantee that this communication is free of virus or that it has not been intercepted or interfered with. If you have received this email in error or have any other concerns regarding its transmission, please notify Postmaster@...
      _________________________________________________________________________________
    Your message has been successfully submitted and would be delivered to recipients shortly.