(This article is about an easy database search for numbers within a range. Simple Database Search (text search) is about an easy database search for matching a string of text.)
An Easy Database Search Implementation
This demonstrates how easy it is to implement a database search for your web site visitors.
Searching to Match a Price Range
The example searches for products matching a price range.
The CGI script and form can be modified to do searches on
other fields and to do different comparisons for matches.
If you need a bit of help with modification,
click here to tell us about your project.
Just Three Installation Steps
The three steps are
Uploading the script and giving it correct permissions.
Creating and uploading the database.
Searching.
Step 1 — Uploading the script and giving it correct permissions
Upload this script into a directory that can run Perl CGI programs. It needs to be uploaded as ASCII/plain text and given 755 permissions. If the location of perl on your server is different than in the script below, the first line of the script needs to be changed.
Note: When you copy this script and paste it into your word processor for saving to your hard drive, the word processor needs to be a plain text word processor like NotePad or BBEdit. Word, FrontPage, and other WYSIWYG and rich text word processors and page makers can introduce script breaking formatting characters.
Step 2 — Creating and uploading the database
Create a tab-delimited plain text database file named "database.txt" and upload it to your server into the same directory the script is at.
database.txt has three fields, in this order:
The listing price of the item.
The URL to the web page describing the item.
The title or name of the item.
Any spreadsheet or database program that can export to tab-delimited plain text file can be used. Access and Excel are just two examples.
Step 3 — Searching
To do a search, a link with a URL like this can be used:
("low" and "high" may be reversed.)
Or, a form like this can be used (note that it's method="GET":
Automatic error correction
The script will automatically remove any characters other than numbers and periods from the "high" and "low" values it is provided with. Your users may type $ or other currency characters with impunity.
The script will automatically reverse the high and low search values if the low value is larger than the high.
Question:
Did you find this article interesting and understandable? How can it be improved?
Your response is anonymous.
When done typing, click anywhere outside the box. [more info]