| Previous | Table of Contents | Next |
Querying on a price range is a little more complex than checking for one exact value match. Since a range is being compared, this actually involves two separate queries criteria elements. The first checks for the low end of the range, and the second checks for the high end of the range. Thus for checking a price range, you would need to have two form variables as shown below:
Lowest Price To Search For:
<INPUT TYPE = "text" NAME = "query_price_low_range"
SIZE = "10" MAXLENGTH = "10">
Highest Price To Search For:
<INPUT TYPE = "text" NAME = "query_price_high_range"
SIZE = "10" MAXLENGTH = "10">
For each of these form variables, there needs to be a separate element in the query criteria arrayone for comparing the low range and another for comparing the high range. The sample @sc_db_query_criteria is presented below.
@sc_db_query_criteria
= ("query_price_low_range|3|<=|number",
"query_price_high_range|3|>=|number");
For the first element, the first field is query_price_low_range and the second field is 3 to match the price. The comparison operator is <= and the data type is number. Basically, this corresponds to the statement that the value entered into the query_price_low_range form field must be less than or equal to whatever price is in the record for the product in order to produce a successful match. For example, if the user has entered 10.00 into the low range field, then a product with a price of 5.00 will not match successfully but a product with a price of 15.00 would match successfully. This is correct behavior because the user wanted to make sure that the lowest price that matched was 10.00.
For the second element, the first field is query_price_high_range, and the second field is 3 to match the price. The comparison operator is >= and the data type is number. This corresponds to the statement that whatever the user has entered into the query_price_high_range form field should be greater than or equal to the price for the record in the database in order to produce a successful match.
Producing a query on the date range follows the same basic logic as producing a query on a price range except that the data type will be date instead of number. An example of a query date range search would be to allow the user to search on the low and high range of an expiration date. Sample HTML to produce the form variables is described as follows:
Lowest Expiration Date To Search For:
<INPUT TYPE = "text" NAME = "query_exp_date_low_range"
SIZE = "10" MAXLENGTH = "10"> <BR>
Highest Expiration Date To Search For:
<INPUT TYPE = "text" NAME = "query_exp_date_high_range"
SIZE = "10" MAXLENGTH = "10"> <BR>
The @sc_db_query_criteria would be assigned using the code below:
@sc_db_query_criteria
= ("query_exp_date_low_range|2|<=|date",
"query_exp_date_high_range|2|>=|date");
The first field of each element corresponds to the form variables query_exp_date_low_range and query_exp_high_range. The second field is 2, which corresponds to the expiration date. Finally, the comparisons are done based on the <= and >= operators with a data type of date. One example, is that the user could fill in 12/15/96 as the low range for the expiration date. If the database has a record that has an expiration date of 12/1/96, then this will not produce a successful match because 12/15/96 is not less than or equal to 12/1/96. However, if the expiration date for a record in the database is 12/17/96, then this will produce a successful match because 12/15/96 is less than 12/17/96.
Note: The date query mechanism built into the Web store relies on the fact that dates must be in the format MM/DD/YY where MM is the month, DD is the day, and YY is the year. The Web store also supports four-digit years as well.
| Previous | Table of Contents | Next |