Link to home
Start Free TrialLog in
Avatar of mrwebmaster
mrwebmaster

asked on

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;
}


Avatar of Kenny
Kenny
Flag of Malaysia image

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.
ASKER CERTIFIED SOLUTION
Avatar of RobWMartin
RobWMartin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ItsMe
ItsMe

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
Avatar of mrwebmaster

ASKER

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

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