Searching databases

I am working on a new search engine in perl cgi. I am wanting the value passed from the HTML page to show all listings in a paticular database.
Now the value in the HTML file to submit a search is 'keywords' where you type in car, outo, or really any keywords and that value is passes on to the .cgi file and listings with the keywords are shown. This operates like any other search engine. If I type the letter "a" of course all listings come up because all listings have an "a" in them.

What I would like to do is pass a value from the HTML page to the .cgi file to show all listings in the database without the user typing any keywords. Just clicking a button would do the trick. I am pasting the code that is being used below. If any one knows the answer to this it would be greatly appreciated.
Thank you in advance
Mr Webmaster

&input;

select(STDOUT);
$| = 1;

&header;

if ($in{'keywords'} !~ /\S/)
{
      print '<center><b>SEARCH TOO GENERAL<br>You must provide keywords for your search.</b></center>';
      &footer;
      exit;
}
elsif (!(-e "$data_dir$in{'category'}.csv"))
{
      print '<center><b>KEYWORDS NOT FOUND<br>Currently no database entries for this category.</b></center>';
      &footer;
      exit;
}

open(DATA, "$data_dir$in{'category'}.csv") || &error('Error opening database file');

@keywords = split(/\s/, $in{'keywords'});

if (length($in{p}) < 1 || $in{p} =~ /\D/)
{
      $in{p} = 1;
}


mrwebmasterAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
RobWMartinConnect With a Mentor Commented:
mrwebmaster,

Rather than having a special value for "keywords," I would use a special submit button.  This is a more direct and user-friendly way.  What if a user starts typing (thus blowing away your special default) then decides (s)he wants all listings?  (S)He would have to type in the special default, then submit. Not good.

Use a special button and test for it.

Assuming the obvious:  That you know how to create a button in HTML, that you know how to test for it in perl, and that you know how to get all listings from your database.

If I've missed the mark on the assumptions, please, specify which of those you need help with.

Cheers,
Rob
0
 
KennyIT Application ExecutiveCommented:
If i get you correctly, what you need to do is to have a default value for 'keywords' in your form. e.g. <input name="keywords" value="leave blank for all listings">

Then, in your perl program, check if the value is the default, and if so, display all the listings in the database.

Hope I understood your question.
0
 
ItsMeCommented:
Hi !
I would create a form using hidden fields and the get method. Hope I understood you right (Of course you can also do a link <a href="/yourcgi.cgi?value=abcdef">click here for abcdef</a>.

then you had to change the perl code so that it reads the url by $ENV{'QUERY_STRING'}

regards
ItsMe
0
 
mrwebmasterAuthor Commented:
I was able to get the job done using
<INPUT TYPE="HIDDEN" NAME="keywords" VALUE="a"
And I believe it works OK. Thank you for your answer.

Mr Steve

0
 
mrwebmasterAuthor Commented:
Mr RobwMartin

I was able to get the job done using
                   <INPUT TYPE="HIDDEN" NAME="keywords" VALUE="a"
                   And I believe it works OK. Thank you for your answer.

I am running into a problem, beings how my page is a search engine I have a number of entries to show 25 or 50 or 100 items depending on how many you choose. suppose the user chooses to see 25 items at a time. then 25 items will show and then when he chooses show the next 25, 25 more are shown.
I am running into a problem when I run out of entries the only choice you have is "previous 25". Works kinda like a back button. Now this is where the problem comes in it is not using the letter as "a" keyword but says the search is to general. How can I give a default value for keywords that work all the time ?
I tried at the top of the script with the other globals to do it by:

#Search keyword
$keyword = 'a';

But this does not work. Cna you suggest a way around this ?
Thank you in advance
Mr Steve

0
All Courses

From novice to tech pro — start learning today.