Gossamer Forum
Home : Products : DBMan : Customization :

Displaying the search criteria on the results page

Quote Reply
Displaying the search criteria on the results page
Let me first apologize if this topic has been covered in previous posts - I've been searching for 2 hours and not found this issue addressed.

I would like to have the html_view_success page display what it was you searched for - along with the "your search returned..." message.

I have tried several things to no avail - closest I got was using the following:

Your search for <b>@hits</b> returned <b>$db_total_hits</b> matches.</font>
|;

Unfortunately that lists all of the search results instead of listing something like this:
Your search for "green" "cars" "1999" resulted in N results.

Can anyone help ?

Thanks!
keienb

Quote Reply
Re: Displaying the search criteria on the results page In reply to
I remember doing this before, but it's been a long time. The hardest thing about doing the search is figuring the best search terms to look for. And, if the post is from a while back, you won't get it, since UBB only gives you 50 returns on a search.

(Lois has created a wonderful index of a lot of the previous mods. I'm going to be working with it to make things easier for all of us -- and I'll add to it as I give stuff to other people.)

Right at the beginning of html_view_success, add

Code:
if ($in{'keyword'}) {
$search_terms = qq|"$in{'keyword'}"|;
}
else {
foreach $column (@db_cols) {
if ($in{$column}) {
$search_terms .= qq| "$in{$column}"|;
}
}
}

Then change

Code:
Your search returned <b>$db_total_hits</b> matches.</font>

to

Code:
Your search for $search_terms returned <b>$db_total_hits</b> matches.</font>

I think that should do it.



------------------
JPD







[This message has been edited by JPDeni (edited March 22, 2000).]
Quote Reply
Re: Displaying the search criteria on the results page In reply to
JPD:

That worked like a charm! Thanks...

I have created a static "search.htm" page, tho and managed a boolean-like search form where it actually searches keywords for three fields simultaneously.

Your coding works beautifully, but only displays the last of the search criteria ... so if I only enter one field - perfect, but if I search all three, it only displays that I searched the last one.

Is this do-able ?

Thanks! Smile

keienb
Quote Reply
Re: Displaying the search criteria on the results page In reply to
I made an error. Smile )

I'll fix it on the original so other folks won't have to read through the whole thing to get the correct code.


------------------
JPD





Quote Reply
Re: Displaying the search criteria on the results page In reply to
Yes! What a difference that dot makes! Smile

Absolutely beautiful!

Thanks for your help Smile

keienb
Quote Reply
Re: Displaying the search criteria on the results page In reply to
JPD:
Thanks again for your quick response yesterday - really did the trick.

Can I mix it up a bit now? Hopefully what I'm asking is relatively simple and I'm just not seeing it - should be a cake walk for "da master," as I've seen you referred to by others Smile

Is there a way to separate the search criteria with "and" or something? I've tried adjusting the code: $search_terms .= qq| "$in{$column}" .... but get a trailing "and," as well?

Hope I not asking for the moon?

Also, while you're on a roll here and this is all falling into place ...
I've tried and re-tried your suggestions from last July when you were helping Elliot with Printable Format (thread: http://www.gossamer-threads.com/scripts/forum/resources/Forum12/HTML/000534.html ) - I get the print_view page fine, headers, footers, and all ... but no data. Any suggestions ??

Sorry for posting about that thread in here, but I thought it might be easier ???

Thanks for any help you can provide! Smile

keienb
Quote Reply
Re: Displaying the search criteria on the results page In reply to
Flattery will get you everywhere! Wink

Separating the search terms is a bit of a problem. The reason I used a space is that, if there are two spaces next to each other on an html page, it doesn't show. Smile

Hmmm. I guess the space didn't show up on the code. I did have a space there, honest!

I guess you could do it, though.

Code:
else {
foreach $column (@db_cols) {
if ($in{$column}) {
$search_terms .= qq| "$in{$column} and "|;
}
}
while ($i <4) {
chop ($search_terms);
++$i;
}
}

I think that will work. If you end up with parts of the last "and", increase the number 4 above. If your last search term is cut off, decrease it.

As for the printable format, make sure that you're looking at the code I entered. Eliot had left out the line

Code:
my ($status, @hits) = &query("view");

That's the line that does the searching. Do you have that?


------------------
JPD





Quote Reply
Re: Displaying the search criteria on the results page In reply to
Hello again JPD!

I've added your code, so it now looks like this:
if ($in{'keyword'}) {
$search_terms = qq|"$in{'keyword'}"|;
}
else {
foreach $column (@db_cols) {
if ($in{$column}) {
$search_terms .= qq| "$in{$column}" and |;
}
}
while ($i <4) {
chop ($search_terms);
++$i;
}
}
_____
I have tried replacing the 4 with 3 and 5 as you suggested ... till get the trailing "and" regardless of the number of search criteria - I have 3 total options, but can search on 1 or 2, if that helps??

As for the printable format- no I didn't have that line, and I must not have it placed correctly? Same results - everything but the data Frown

Any other ideas?

keienb

P.S.
Thanks again for your help! I'll be happy to show you what this all looks when we get it working.
Quote Reply
Re: Displaying the search criteria on the results page In reply to
You must truly be an angel... how else could you function with no sleep? Smile

That last bit of code, as you said, worked beautifully! Thanks ... it's perfect.

As for the Printable bit ... I have added the following to my db.cgi as you had posted:
Code:
sub print_view {
# --------------------------------------------------------
# This is called when a user is searching the database for
# viewing. All the work is done in query() and the routines just
# checks to see if the search was successful or not and returns
# the user to the appropriate page.

my ($status, @hits) = &query("view");
if ($status eq "ok") {
&html_print_view(@hits);
}
else {
&html_view_failure($status);
}
}

You can view what I have for the html.pl, since it is quite lengthy... http://www.tkdesignz.com/dbman/htmlpl.txt

You may also notice in the html_view_success and the html_print_view I have attempted to put the current date? Perhaps you can shed some light on this one for me, as well? I don't understand why in my "add_form" the "&get_date" works just fine, but trying to get it to print out like this:
Code:
On <b>$get_date</b>, Time\$heet found <b>$db_total_hits</b> records matching your request for: <b>$search_terms</b>.</font>
|;
I get no date display at all ... just like the missing data on the print_view

Any suggestions?

Thanks again for all your superb help! Smile
Quote Reply
Re: Displaying the search criteria on the results page In reply to
Well, if that doesn't work, we'll try something else. Smile

It needs to work whether there are 1, 2, 5 or 20 search terms.

Try this. Instead of

Code:
else {
foreach $column (@db_cols) {
if ($in{$column}) {
$search_terms .= qq| "$in{$column}" and |;
}
}
while ($i <4) {
chop ($search_terms);
++$i;
}
}

use

Code:
else {
# schlep search terms into an array
foreach $column (@db_cols) {
if ($in{$column}) {
push (@search, $in{$column});
}
}
# put quotation marks around each term
foreach $term (@search) {
$term = '"' . $term . '"';
}
# put and between the terms
$search_terms = join(' and&nbsp',@search);
}

I just tested this out and I got it to work. Smile

As for the printout, I'm not sure what's wrong. I think I'm going to have to ask you to post your code -- or if it's quite long, copy it to a .txt file and place it where I can access it from the web. Just put it into any directory where you would place html files.


------------------
JPD





Quote Reply
Re: Displaying the search criteria on the results page In reply to
Hello again!

I've managed the date problem - all sorted out now Smile

I'm still having problems with the Printable Format, tho ... if you have time?

Thanks again for your great help!

keienb Smile
Quote Reply
Re: Displaying the search criteria on the results page In reply to
Glad you got the date thing worked out.

(I do sleep. It's just at odd hours. Smile )

In your file, I see a line:

&html_printout(@hits);

But I don't find a sub html_printout. Is it in another file?


------------------
JPD





Quote Reply
Re: Displaying the search criteria on the results page In reply to
Can you say OOPS?

I must have gotten that code from the previous threads about printable format and I completely missed that line... I do not have &html_printout anywhere.

I'm not sure, tho that the &html_printout should be in the view_success??

What concerned me was, as I'm sure you noticed, I copied exactly "html_view_success" and made a sub "html_print_view" ... and had the submit button call the print_view ... with both subs identical, why would one display the data and the other be blank ?

I need a bit more help when you have the time Smile

Thanks again!

keienb
Quote Reply
Re: Displaying the search criteria on the results page In reply to
First off, how are you determining that the user wants a printout format of search results instead of a web-based display? I would expect there to be something in sub html_view_search, but I didn't see it.

(I really need to "follow the path" of the script in order to figure things out.)


------------------
JPD





Quote Reply
Re: Displaying the search criteria on the results page In reply to
Sorry for all the confusion... I have just had the "lightbulb" thingee go off over my head Smile

The mystery code "&html_printout" is left-over from my attemtps to use a checkbox on the search form to cause the results to be printed to file - guess I missed them, since they neither worked, nor caused any problem.

Next, my thought was to just duplicate the results - identical to the html_view_success ... for now, at least. If I can manage that, I should have no problem adjusting the from there to remove the header, footer and massaging the display (smaller font, etc) to cause more data to be printable per page.

It was my intention to use a submit button, either on the search form 0R on the view_success (maybe even both) to cause the the "compressed" results to be displayed. I apologize that the text file that I posted for you to see had already had the button code removed.

Have I explained myself better, I hope?
Sorry if I've become a pain... guess it's safe to tell you know that I'm very new to Perl Smile

If I've missed anything in my definition, please let me know and I'll be happy to post a new copy of the file for you to see.

Thanks again - you ARE a God-send ! Smile

-keienb
Quote Reply
Re: Displaying the search criteria on the results page In reply to
No problem. I understand what things are like when one is new. Smile

First, decide where you want to put the button or link to print out the data in compressed form. If you have it on the search form, it should be a submit button with the name "printout." If you have it on the search results, you'll either have to have a form with hidden fields to pass all of the search terms, or a link that includes all of the search terms plus &printout=1. (I'd vote for the form, since it's a little easier.)

Following the path from the button (or link) to db.cgi, you'll need to add a line to sub main in db.cgi, if you don't already have it there:

Code:
elsif ($in{'printout'}) { if ($per_view) { &print_view; } else { &html_unauth; } }

You already have sub print_view in your db.cgi file. That looks fine.

Back in html.pl, if results are found from the search, you'll be sent to sub html_print_view. You'll need to do some work on that subroutine, depending on what you want to do. Are you just wanting a text page to be printed out, or do you want them to print an html page?

At any rate, you don't need

Code:
if ($in{'printout'}) {
&html_printout(@hits);
return;
}

because the only way the person could have gotten to that subroutine was if $in{'printout'} had a value in it.

You also do not need that code in sub html_view_success, because, if $in{'printout'} had a value, the user would not be going to that subroutine.

So really all you need to do is set up sub html_print_view to print out your printable text. Along with adding the button or link to actually get to the printable text. Smile



------------------
JPD







[This message has been edited by JPDeni (edited March 25, 2000).]
Quote Reply
Re: Displaying the search criteria on the results page In reply to
JPD,

You have been most helpful Smile

Your last post worked like a charm - for the moment, I have only removed the header & footer from the html_print_viewdisplay.

I am curious about returning the results as text instead of html ? Could definitely fit more lines per page!

One final question (I hope ... I feel like I've been asking for way too much)...for the printable view, is there a way to force ALL hits to be displayed on one page? So there is no "$db_next_hits" ? I realize this has potential to be a HUGE return, but it will work for my needs.

Again, I thank you for your superb help! Smile

-keienb

P.S.

I need to learn much more before attempting the following, but is it even possible?

I would eventually like to be able to search by field2 and have the results sorted by field1 ... that part is easy enough, but then to have that displayed with subtotals of field3 ... I already have a totals line for that field, but it currently only totals the entire results page.
Example:

bob inhouse 4.0 1/1/2000
bob inhouse 2.5 1/2/2000
------------------------------------
subtotal 6.5

john inhouse 3.0 1/1/2000
john inhouse 4.5 1/2/2000
------------------------------------
subtotal 7.5

Just a though ... is dbman even capable of such subtotalling ?

Smile
Quote Reply
Re: Displaying the search criteria on the results page In reply to
To print out text instead of an html page, you can use the following subroutine:

Code:
sub text_print_headers {
# --------------------------------------------------------
# Print out the headers if they haven't already been printed.
if (!$html_headers_printed) {
print "Content-type: text/plain\n\n";
$html_headers_printed = 1;
}
}

In your html_print_view subroutine, use

&text_print_headers;

instead of

&html_print_headers;

Then don't use any html formatting at all on the page.

Having said that, I need to tell you this. I use this on my Configurator and some folks have had problems with it. All of the people who had problems seem to be using Internet Explorer, but I just tried it with IE and I didn't have any problems. I'm not sure why some folks do and some don't.

To make it print out all of the records on one page, add the following line to sub print_view:

$in{'mh'} = 100000;

Put it just before

my ($status, @hits) = &query("view");

That should be enough to cover all of the records returned from a search. (If you have any more than that, you might want to look at using DBMan-SQL. Smile )

Regarding the search/sort/subtotal question -- can I assume that field1 (the field you're sorting by) is the field where we would find "bob" and "john"? If so, yes, you can do what you want. Why don't we wait until you get the other issue cleared up, though, and then we'll investigate this further in a new thread. Smile



------------------
JPD





Quote Reply
Re: Displaying the search criteria on the results page In reply to
Thanks again for your advice.

I have "resolved" the issue of printing all of the records, similar to what you suggested, but I went way around it by creating another line in the 'footer' for "reports" to call the print_view - from there I set the max hits to hidden and put in a huge number - seems to work great! I will add back the Printable Format button to the regular search form, as well, having gotten this information from you, that way both will be accessible Smile

I'll have to get to work on the text portion and see if I have any difficulty with IE ?

Thanks again ... any suggestion for what to call the next thread to address those other issues down the road ??

Your help is greatly appreciated! Smile

-keienb
Quote Reply
Re: Displaying the search criteria on the results page In reply to
Naming threads is always a problem. "Subtotals in search results"?

You might put a warning on your site somewhere that there are occasional problems with IE and the text printout. Tell users, if they have a problem, to use Netscape. That's the best I can do.

There is another possibility that you might try. (I haven't tried it yet myself, so I don't know if it will work.)

Go back to using

&html_print_headers;

and put in the beginning html code:

Code:
print qq|
<html>
<head>
<title>$html_title: Printout </title>
</head>

<body bgcolor="#FFFFFF">|;

Then have all of the rest of your data preformatted on the page:

Code:
print "<pre>";

After you print out your data, close off your tags:

Code:
print "</pre></body></html";

If you try it, let me know how it works. I'll see if I can use it to cut down problems with the Configurator.


------------------
JPD





Quote Reply
Re: Displaying the search criteria on the results page In reply to
Thanks JPD!

Sounds like it's worth a try, but it's gonna have to be a new day ... think it's niteynite time for me Smile

I'll give it a shot tomorrow and let you know where it got me.

-keienb
Quote Reply
Re: Displaying the search criteria on the results page In reply to
Hiya JPD:

I don't know if there's something I've missed, overlooked or just don't know about the preformatting ... but my page is all kinds of sideways using that last bit of code. All of the data displays - it's just really messy, but equally as messy whether IE or Netscape, if that helps you any Smile

I'll keep at it!

-keienb
Quote Reply
Re: Displaying the search criteria on the results page In reply to
You might want to just go with the other way, then. Be aware that your spacing is going to be very tricky whether you use a text format or preformatting.

You might do better to just use regular html formatting with a specific font.


------------------
JPD





Quote Reply
Re: Displaying the search criteria on the results page In reply to
I think your last suggestion was the best ... I get the nicest looking results from html, so I'm going to leave well enough alone and move on to the next task .... look for a new thread! Smile

-keienb