Showcase and discover digital art at yex

Follow Design Stacks

Subscribe to our free newsletter to get all our latest tutorials and articles delivered directly to your inbox!

Step 6. Fine Tuning the Searches

Step 6. Fine Tuning the Searches

Your dynamic Search form is working, but now you need to plan for all the ways a user might try to use it. For instance, what if the user calls the page directly, or enters nothing for search criteria? At this point your Search page is looking for a “request parameter”, and it has to match the “lname” exactly. GoLive has given us a great starting place, and from here a few additional steps will cover the contingenes:

  1. Rename your text field on your search form to “keyword”.
  2. Change the Table pop up menu to Custom SQL in the Content Source Inspector
  3. Select the text in the SQL edit box and delete it.
  4. Type or paste the text below into the SQL box:

    For ASP:

    select * from golive_test where lname like  
    '%{Request.QueryString("keyword")}%' or fname like  
    '%{Request.QueryString("keyword")}%' or phone like  
    '%{Request.QueryString("keyword")}%'

    For PHP:

    select * from golive_test where lname like  
    '%{@$GLOBALS["keyword"]}%' or fname like '%{@$GLOBALS["keyword"]}%'  
    or phone like '%{@$GLOBALS["keyword"]}%'

    This snippet of source code transforms the Search_Results Content Source into a practical search engine. The above code basically says: “look at what the user typed into the search field and see if it matches anything in any of the fields of all the records. And while you’re at it, return the matching records and make them available as content for this page.” This is what we want! If nothing is typed into the search box, or if the page is called directly with no previous page, ALL records are returned. Anything typed into the search box will be matched to the database fields.

Note that the “select * from golive_test” statement means to select everything in the database named ‘golive_test’. The ‘where’ statement sets you up to make some qualifications. The ‘like’ word specifies a partial match, so it doesn’t have to be exact. The ‘%’ symbol is a wildcard that tells it to match any number of characters. Because there are ‘%’ symbols on both ends of the expression, the search will match every record if nothing is typed into the search box or if the page is called first with no previous page. It’s kind of like asking “show me records that contain any number of characters + what the user typed + any number of characters”. That sounds like word math to me! If the user typed nothing, or if the page is called first, the word math for that would be: Records = ‘any number of characters’ + 0 + ‘any number of characters’. Hey… every record qualifies for that!

Block Navigation

Now you want to add some Block Navigation, which is a cool way to deliver users their search results. Block Navigation lets you specify how many records per page you want to display, and includes links that allow the user to browse easily through multiple pages of results.

Start by adding another blank Content Source to the header of your page. Fill out the fields as follows:

  1. Description: Block (again, name this anything you want, but this Content Source will provide our Block Navigation)
  2. Type: Navigation Block View
  3. Content Source: “Search_Results” (or whatever you named that first Content Source.)
  4. Create a regular 1 row x 2 cell table underneath the search results table – in the first cell type “Records:”
  5. Drag a Repeat Cells object from the Dynamic Content palette into the second cell of the 1×2 table
  6. Delete all but one cell of the Repeat Cells table and type “x-y” in that cell
  7. Select the ‘x’ and bind it to the “Block” Content Source with the filed set to “First”
  8. Select the ‘y’ and bind it to the “Block” Content Source with the filed set to “Last”
  9. Select the whole ‘x-y’ text and link it to your Search page
  10. In the Dynamic Bindings palette Click “Bind Link Destination To” and set the Field to “Link_URL”

What you now have is a page that is looking for searches and doing block navigation. When someone types in a keyword like “John,” all the records that contain “John” in the fields you indicated will be displayed. It also will use the “Block” Content Source to provide those handy links that allow a user to bounce between multiple pages of results. This is Block Navigation in the form “Records: 1-5 6-10 11-13, etc.” Very cool! And you thought you couldn’t program!

Tip: Remember to set your posting method for your search form to “Get” as “Post” isn’t compatible with Blockavigation.

At this point you can use the GoLive Preview Tab to see results, but note that your page is not live, so you really are only previewing. If you get an error message when trying to display a custom search, try previewing it in a browser. Also, GoLive 6.0.1 displays this custom code correctly in Preview mode, so ensure you’ve done the upgrade.

Comments