[WEB4LIB] Modified "get" action for forms?

Araby Greene araby at unr.edu
Tue Nov 7 18:55:53 EST 2000


Yes, you can generate a query that uses only fields with input from a search
form. I had to muddle through that same question recently for a search form
that uses 3 fields and the option of and/or with a second search term for
the first two fields. Search results are a list of titles with agency,
links, and callnumber from our (uncataloged) Nevada docs database. The query
string includes only those fields that have input. It uses ASP and VBScript,
though the same idea should work for PHP and mySQL.

Conceptually, it's simple: use IF statements to test for input that <> "",
then concatenate the fields that pass the test to the sql query string.
Getting the syntax exactly right is the only tricky part.

To keep it simple, the script first tests for a blank search form (i.e.,
each input field = "") and requires that the user enter at least one search
term. A blank title field is allowed so that the user can search for ALL
titles, limited by agency or callnumber (because the database is small, only
about 2300 records). This also allows easy coding of the first condition in
the WHERE statement which matches either a blank title or title search
term(s). Wildcards are at both ends of the title search term.

After that, use:
If [field] <> "" Then
strSQL = strSQL & " AND (condition) "
End If
If [field] <> "" Then
strSQL = strSQL & " AND (next condition) "
End If
and so on
Concatenate the ORDER BY part at the end.

Then loop through the recordset for results.

The URL is
http://www.library.unr.edu/depts/bgic/guides/government/nevada/nevada.html

Hope this helps.
-araby
________________________
Araby Greene
araby at unr.edu
Web Development Librarian
Getchell Library/322
Univ. of Nevada, Reno
http://www.library.unr.edu/

----- Original Message -----
From: "Chris Shaffer" <shaffer at uic.edu>
To: "Multiple recipients of list" <web4lib at webjunction.org>
Sent: Tuesday, November 07, 2000 2:22 PM
Subject: [WEB4LIB] Modified "get" action for forms?


> I have a database search form with many input fields, only a few of which
> are used in the average search.  I'd like the search logic to be embedded
> in the URL so that search results pages can be bookmarks or
> favorites.  However, action="get" puts all the fields in the URL, which
> results in a very long URL.  I'd like to generate a URL that only includes
> non-null input fields.  Is there any way to do this that 1) does not use
> javascript and 2) does not disable the browser back button via redirect?
>
> FYI, our web server is Unix, Apache, PHP, MySQL.
> -----
> Chris Shaffer, Technology Coordinator
> National Network of Libraries of Medicine, Greater Midwest Region
> Library of the Health Sciences, University of Illinois at Chicago
> shaffer at uic.edu     http://www.nnlm.nlm.nih.gov/gmr/
> 312-996-2464 (voice)     312-996-2226 (fax)



More information about the Web4lib mailing list