I've kinda got a mix of you guy's suggestions. This is totally a test script here. I'll be using HTML::Template for all the html and will be cleaning up a few things, but to give you a general idea, here's what I made. It seems to work perfectly for my purposes. I tested it with as many as 3000 entries, even though it isn't likely that it will EVER have more than 500 (300 is what we expect). Comments are welcome!

#!c:/perl/bin/perl.exe -w use strict; use CGI::Carp qw(fatalsToBrowser); ##################################################################### # CONFIGURATION ##################################################################### my %OPTIONS = ( databaseDir => "c:/", ); my %makes = ( 1 => 'all', 2 => 'Chevrolet', 3 => 'Ford', 4 => 'Pontiac', 5 => 'Honda', ); my %models = ( 1 => 'all', 2 => 'Car', 3 => 'Truck', 4 => 'Van', 5 => 'Mini Van', ); my %years = ( 1 => 'all', 2 => '1980-1985', 3 => '1986-1990', 4 => '1991-1995', 5 => '1996-2000', 6 => '2000-Present', ); my %sortBy = ( # The numbers here correspond to the place in the output hash string. Make => '0', Model => '1', Price => '2', Year => '3', ); ##################################################################### # END OF CONFIGURATION ##################################################################### use DB_File; use CGI; my $query = new CGI; my $action = $query->param('action'); my $id = $query->param('id'); my $sortBy = $query->param('sortBy'); my $make = $query->param('make'); my $model = $query->param('model'); my $year = $query->param('year'); my $price = $query->param('price'); my %OUTPUT; print $query->header; my %ACTIONS = ( search => \&search, display => \&display, ); if ($action) { # If an action is given, active the appropriate subroutine $ACTIONS{$action}->(); } else { # If no action is given, display the update page $ACTIONS{'search'}->(); } ##################################################################### # SUBROUTINES ##################################################################### sub check { if($_[0] == 1) { return(1); } elsif($_[0] == $_[1]) { return(1); } else { return(0); } } sub checkPrice { if($_[0] <= $price) { return(1); } else { return(0); } } sub search { print "<html><head><title>Output Page</title><style type=\"text/cs +s\"><!-- .header { font: bold 10pt verdana; color: white; background: + orange; } .caption { font: 8pt verdana; color:black; } --></style></ +head><body><TABLE width=600 cellpadding=0 cellspacing=0>"; my %OUTPUT=(); my $counter = 0; tie (my %INDEX, "DB_File", "$OPTIONS{databaseDir}/index.db", O_RDW +R|O_CREAT, 0755, $DB_HASH) || die "Cannot open database: $!\n"; tie (my %DATABASE, "DB_File", "$OPTIONS{databaseDir}/database.db", + O_RDWR|O_CREAT, 0755, $DB_HASH) || die "Cannot open database: $!\n"; foreach my $key (keys %INDEX) { my @key = split(/\|/, $INDEX{$key}); if(&check("$make","$key[0]")) { if(&check("$model","$key[1]")) { if(&check("$year","$key[2]")) { if(&checkPrice("$key[3]")) { # Form of output string: Make | Model | Price +| Details (from database. in this case, year|description) $OUTPUT{$key} = "$makes{$key[0]}|$models{$key[ +1]}|$key[3]|$DATABASE{$key}"; $counter++; } } } } } if($counter == 0) { print "<td>No cars matched your search. Please try again.</td +>"; } else { print "<tr><td colspan=4 align=right class=caption>Click on th +e header to sort by that category</td></tr>"; print "<tr> <td class=\"header\"><a href=\"carsearch.cgi?sortBy=Make\& +make=$make\&model=$model\&price=$price\&year=$year\">Make</a></td> <td class=\"header\"><a href=\"carsearch.cgi?sortBy=Model\ +&make=$make\&model=$model\&price=$price\&year=$year\">Model</a></td> <td class=\"header\"><a href=\"carsearch.cgi?sortBy=Year\& +make=$make\&model=$model\&price=$price\&year=$year\">Year</a></td> <td class=\"header\"><a href=\"carsearch.cgi?sortBy=Price\ +&make=$make\&model=$model\&price=$price\&year=$year\">Price</a></td> </tr>"; foreach my $key (sort { my @a = split(/\|/, $OUTPUT{$a}); my @ +b = split(/\|/, $OUTPUT{$b}); $a[$sortBy{$sortBy}] cmp $b[$sortBy{$so +rtBy}]; } (keys %OUTPUT)) { my @details = split(/\|/, $OUTPUT{$key}); print "<tr><td><a href=\"carsearch.cgi?action=display\&id= +$key\">$details[0]</a></td>"; print "<td>$details[1]</td>"; print "<td>$details[3]"; print " <td>\$$details[2]</td></tr>\n "; } } print "</TABLE></body></html>"; untie (%DATABASE); untie (%INDEX); } sub display { tie (my %INDEX, "DB_File", "$OPTIONS{databaseDir}/index.db", O_RDW +R|O_CREAT, 0755, $DB_HASH) || die "Cannot open database: $!\n"; tie (my %DATABASE, "DB_File", "$OPTIONS{databaseDir}/database.db", + O_RDWR|O_CREAT, 0755, $DB_HASH) || die "Cannot open database: $!\n"; my @key = split(/\|/, $INDEX{$id}); my @details = split(/\|/, $DATABASE{$id}); print "Make: $makes{$key[0]}<br>"; print "Model: $models{$key[1]}<br>"; print "Year: $details[0]<br>"; print "Price: \$$key[3]<p>"; print "Description: $details[1]"; untie (%DATABASE); untie (%INDEX); }

In reply to Re: Question about properly laying out a database by Stamp_Guy
in thread Question about properly laying out a database by Stamp_Guy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.