Skip to main content

Setting the Query Variable

Finally, we set the value of the Query variable. If the value of CatName is not a zero-length string, then CatID picks out a FilmCategory instance in the database. We then execute the TopCategory query. If the value of CatName is a zero-length string then either there was no cookie or its value did not correspond to the ID of a FilmCategory instance. In either case we execute the TopFilms query.

Note that as originally defined the TopFilms query did not accept any parameters. Since this code will attempt to pass a parameter to TopFilms we must modify the query so that it accepts a “dummy” parameter, that is a parameter that will not actually be used when the query executes. Click the “Hands On” graphic to see the modified TopFilms query:

generated description: handson.gif

—TopPicks.csp—
TopPicks.csp
<html> <body>
<script language="cache" runat="server">
    set CatID = %request.GetCookie("CacheCinemaLastCategory")
    set CatName = ""
    if (CatID '= "") {
        set Cat = ##class(Cinema.FilmCategory).%OpenId(CatID)
        if (Cat '= "") {
            set CatName = Cat.CategoryName
        }
    }
    if (CatName '= "") {
        set Query = "TopCategory"
    } else {
        set Query = "TopFilms"
    }

</script>
<font color="#0000FF" size="+2"><b>Today's #(CatName)# Top Picks </b></font>
<table border=0>
<csp:query 
        name=FilmList 
        classname="Cinema.Film" 
        queryname='#(Query)#' P1=#(CatID)#>
<csp:while condition="FilmList.Next()"> ... </csp:while>
</table>
</body> </html>
FeedbackOpens in a new tab