CGI and Perl

Displaying Search Results

Now that you've seen how to set up the search pages, you need to figure out how to display the results from the search operation. To display results, you need a few more MiniVend tags that enable you to display a list of items. This page, coded in Listing 13.4, can be kept fairly generic as you will see. Most of the text on the page is filled in by MiniVend based on the contents of your product database.

Listing 13.4. The results display page.

<HTML><HEAD>
 <TITLE>Search Results</TITLE>
 </HEAD>
 <BODY>
 <H1>
 Search Results
 </H1>
 <P>
 [finish-order]
 <P>
 <H2>
 [more-list]
 Matches [matches] of
 [/more-list]
 [value mv_search_match_count]
 items found</H2>
 <P>
 <TABLE BORDER>
 <TR>
 <TH>Item #</TH><TH>Description</TH><TH></TH><TH></TH><TH>Everyday Low Price</TH>
 </TR>
 [search-list]
 <TR>
 <TD><B>[item_increment]</B></TD>
 <TD>[item-description]<BR></TD>
 <TD>[item-link]</TD>
 <TD>[order [item-code]]<STRONG>Order</STRONG>[/order]</TD>
 <TD><B>Our Everyday Low Price $[item-price]</B><p></TD>
 </TR>
 [/search-list]
 </TABLE>
 <HR>
 [more-list]
 <B>There's even more to choose from!:</B><BR>
 [more]
 <HR>
 [/more-list]
 <TABLE>
 <TR>
 <TD>[page browse]Browse by Category[/page]</TD>
 <TD>[page search]Search[/page]</TD>
 <TD>[page catalog]Home[/page]</TD>
 </TR>
 </TABLE>
 <P>
 </BODY></HTML>

The first tag that needs explanation here is the [finish-order] tag. This tag inserts a link to the order page, giving the customer a quick way to place his or her order. If no items are in the customer's shopping cart, this tag is ignored. Another interesting tag in this page is [more-list]. This tag directly relates to the mv_matchlimit of the previous page. It provides the user with a scrollable list of items. Of course, this list comes into play only if the mv_matchlimit value is exceeded. The [matches] tag displays the current range the customer is viewing. If you've done any kind of Web searching, you should already be familiar with this concept.

After displaying the number of items found using the [value] tag along with the mv_search_match_count variable, you begin listing the items by using the [search-list] tag. Once inside the [search-list], you can represent each item in any way that HTML allows. One of the best ways to display this type of list is to use a table, as done in Listing 13.4. [item-increment] specifies the index number of the item within the search results. [item-description] displays the item's Description field value from your product database. [item-link] provides a quick link to more information about that item. The way this link works is pretty cool. You can create a page called flypage.html, which will be the template for generating this page on the fly from the information in your database. The next column gives the user a link to be able to order the item. It uses the [order] tag together with the [item-code] tag. The [order] tag provides a link to the order page, enabling the user to place his or her order. The [item-code] is a necessary parameter to the [order] tag, which is extracted from the product database. This parameter tells MiniVend which item is being ordered. The last tag within the search list is [item-price], which, of course, displays the price of the item as listed in the product database. Figure 13.4 shows search results using a textual search on the database, and Figure 13.5 shows results using a category search.

Figure 13.4. The search results from a textual search.

Figure 13.5. The search results from a category search.

You are now close to finished with your shopping site. The last major page to define is your order page. On this page, you specify what information you want to obtain from the customers when they place their orders and get information about items in their virtual shopping carts.

by BrainBellupdated
Advertisement: