![]() |
| |
![]() |
||
|
![]() |
|||||||||||||||||||||||||||||||||
|
More Lasso Examples At the suggestion of a reader, I have decided to focus this article on Lasso. I will introduce four examples that illustrate some of the things that are possible with Lasso. See how receptive I am to suggestions?
Smart Searching of multiple fields In order to allow for intelligent searching of the database through the simplest interface, I developed a solution with lasso to use one field to search multiple fields in a database. The idea is actually pretty easy to figure out once you understand the basic construct. The main motivation for the one field search method was because of the limitations of Sherlock 2. I implemented a more complex version of this example for the previous incarnation of this site (Apple Wizards Mini-Reviews). Here is the code sample:
The first two lines are just code to set variables with lasso. In the first line we are setting the variable "Rating" to the value that was given to the field "Product_Name" on the page that proceeded it. [var_set:"Rating"=form_param:"Product_Name"] With this simple syntax we are able to grab any of the data that the user submitted on the page before this. The form_param:"Product_Name" code in this case actually refers to the only field in the search form. In the second line we attach the same value to the new variable "Reviewer_Name". [var_set:"Reviewer_Name"=form_param:"Product_Name"] The point of
doing this is to make the code more readable when we do each of the searches.
The second group of code looks at the rating value and if it is the keyword
gold or gold bar than a new variable "Rating_calc" is set equal to 3.
[if: var:"Rating"=="gold"||var:"Rating"=="gold bar"] [var_set:"Rating_calc"="3"]
[/if] The primary reason for doing this is that in the database the
Rating is actually stored as a number. By looking for these keywords it
can be easy to point them to real value in the database. In my last column(Link
to last column) I described the inline search code in detail. In this
case I will only elaborate on the important parts for my example case.
[inline: search, database="AW_Mini_Review", layout="Everything",
It is worth noting two things in the above code. The first is the search
is actually being done on the variable that we set above. It is looking
for the name of the reviewer in the review database. The default search
will find the full name or partial names (for example all the "Marc"'s if
that is my search term). The second thing to note is that the the database
is sorted on the Reviewer name. This will give us the results back in an
order that is most helpful if we match more than one name. In this next
section of code a new type of variable is set.
[Records] [while: loopcount<=(list_itemcount:
"RecID_List")] [if: (RecordID_Value)==(List_GetItem:'RecID_List',
Lasso has a variable type called a list which helps to organize a bunch
of related items. In this case the goal of this code is to twofold. First
we want to check to see if the item that we have found in the database is
not one that we have already returned. In order to do that we use the code
[while: loopcount<=(list_itemcount:
"RecID_List")]
This is a loop that we execute enough times to compare the current found
record to each of those that have already be added to the list. If the variable
isn't found than the skip variable is never set and the second group of
code is executed.
[if: var:"skip"!="1"] [List_AddItem:'RecID_list',(RecordID_value)]
[/if] The only thing this does is add the item to the list. We then
move on to the last section of the code which displays the item (again
if it was added to the list).
Display code for item.
[/Records] [/inline]
I have left off the actual display code to keep the example much simpler. If you are curious I do have the link to all the real page. (Link to page.)
Multiple database Actions in One Page By copying and expanding the examples above the example page actually performs 5 different types of searches in one page. It searches for Reviewer Name, Date of Review, Rating for Review, Category, and portions of the Product Title (for example search for Gold with the following form)
Dynamic Display of the Interface In the case of my Online Testing System, the interface itself is determined by one field in the User database. The default value gives the user the simple student interface. A different value in the field gives the user the Faculty interface. The Faculty interface is much more complex, but it gives them better control of administering and creating tests. There is also a third interface which is accessible only by the admin. For obvious reasons I can't give a link to it. Keep in mind that all the decision making as far as which interface to display is done by Lasso at the time the page is requested by the user. One value in the database allows access to 3 totally different approaches to interacting with the system. As was discussed above the code to differentiate the 3 types of users is a simple if/else statement.
My next column... In my next column I will look into Lasso and FileMaker Security. I will discuss some of the techniques I have used to help to secure my site. |
||||||||||||||||||||||||||||||||||
|