##################################################################### # Price Range Select Field # by JPDeni # Written 28 Apr 2000 ###################################################################### # # This will allow you to build a select field by which your users can search for a range of prices in your database. # ###################################################################### # # 1) Set up a field called 'Price' in your .cfg file. When you enter prices, do *not* include commas or dollar signs. Set the # field_type of the Price field to 'numer'. Create a text field in sub html_record_form to input the price of the item. # # 2) In the html.pl file, create a separate form for searching. Copy sub html_record_form and paste it directly below the current one. # You will now have two subroutines that are identical. Rename the second subroutine as: sub html_search_form # Remove any fields that you do not want users to be able to search by. Replace the text input field for the Price field with the following: # You may, of course, use any ranges that you wish. Just look carefully at the pattern here and follow it. # # 3) In sub html_view_search, change &html_record_form(); # to &html_search_form(); # In sub html_view_failure, change &html_record_form(%in); # to &html_search_form(%in); # 4) In db.cgi, sub query, just after local (%sortby); # add if ($in{'Price'}) { unless ($in{'Price'} eq "*") { ($in{'Price-gt'},$in{'Price-lt'}) = split (/-/,$in{'Price'}); $in{'Price'} = ''; } } # 5) If you would like to add commas for prices over 999 and a dollar sign, add the following to sub html_record (and/or # sub html_record_long, if you're using the short/long display mod). After my (%rec) = @_; # add 1 while $rec{'Price'} =~ s/(\d)(\d{3})\b/$1,$2/; # add commas $rec{'Price'} = "\$" . $rec{'Price'}; # Add dollar sign