Professional Web Applications Themes

Two Menu-Type Form on one page! - Coldfusion - Advanced Techniques

OK, Coldfusion Gurus, let's see how good you are! I have two forms that access a database, both are menu-type forms. One allows the user to choose by city, the other by alphabetical. The page can be viewed at: http://69.2.200.145/mhls/parks.html. What is the best way to go about this using Coldfusion? I was thinking for the alphabetical list to use <cfswitch> and <cfcase> statements and displaying them with a <cfloop> statment. I was going to use a simple SQL statement and <cfoutput query="city"> tag for the city form. The alphabetical list is where I am having my issues at the ...

  1. #1

    Default Two Menu-Type Form on one page!

    OK, Coldfusion Gurus, let's see how good you are!

    I have two forms that access a database, both are menu-type forms. One allows
    the user to choose by city, the other by alphabetical. The page can be viewed
    at: http://69.2.200.145/mhls/parks.html. What is the best way to go about
    this using Coldfusion? I was thinking for the alphabetical list to use
    <cfswitch> and <cfcase> statements and displaying them with a <cfloop>
    statment. I was going to use a simple SQL statement and <cfoutput
    query="city"> tag for the city form. The alphabetical list is where I am
    having my issues at the moment.

    Here is the asp to process the form page, and followed is the asp to display
    it:

    <%
    Dim Connect, OnMenu, OnMenu2, Query2, Query, alphalist
    alphalist = Request.form("Select2")
    select case alphalist
    case "A to B"
    Query1 = "SELECT * FROM parks WHERE Name LIKE 'A%'"
    Query2 = "SELECT * FROM parks WHERE Name LIKE 'B%'"
    index1 = "A"
    index2 = "B"
    case "C to D"
    Query1 = "SELECT * FROM parks WHERE Name LIKE 'C%'"
    Query2 = "SELECT * FROM parks WHERE Name LIKE 'D%'"
    index1 = "C"
    index2 = "D"
    case "E to F"
    Query1 = "SELECT * FROM parks WHERE Name LIKE 'E%'"
    Query2 = "SELECT * FROM parks WHERE Name LIKE 'F%'"
    index1 = "E"
    index2 = "F"
    case "G to H"
    Query1 = "SELECT * FROM parks WHERE Name LIKE 'G%'"
    Query2 = "SELECT * FROM parks WHERE Name LIKE 'H%'"
    index1 = "G"
    index2 = "H"
    case "I to J"
    Query1 = "SELECT * FROM parks WHERE Name LIKE 'I%'"
    Query2 = "SELECT * FROM parks WHERE Name LIKE 'J%'"
    index1 = "I"
    index2 = "J"
    case "K to L"
    Query1 = "SELECT * FROM parks WHERE Name LIKE 'K%'"
    Query2 = "SELECT * FROM parks WHERE Name LIKE 'L%'"
    index1 = "K"
    index2 = "L"
    case "M to N"
    Query1 = "SELECT * FROM parks WHERE Name LIKE 'M%'"
    Query2 = "SELECT * FROM parks WHERE Name LIKE 'N%'"
    index1 = "M"
    index2 = "N"
    case "O to P"
    Query1 = "SELECT * FROM parks WHERE Name LIKE 'O%'"
    Query2 = "SELECT * FROM parks WHERE Name LIKE 'P%'"
    index1 = "O"
    index2 = "P"
    case "Q to R"
    Query1 = "SELECT * FROM parks WHERE Name LIKE 'Q%'"
    Query2 = "SELECT * FROM parks WHERE Name LIKE 'R%'"
    index1 = "Q"
    index2 = "R"
    case "S to T"
    Query1 = "SELECT * FROM parks WHERE Name LIKE 'S%'"
    Query2 = "SELECT * FROM parks WHERE Name LIKE 'T%'"
    index1 = "S"
    index2 = "T"
    case "U to V"
    Query1 = "SELECT * FROM parks WHERE Name LIKE 'U%'"
    Query2 = "SELECT * FROM parks WHERE Name LIKE 'V%'"
    index1 = "U"
    index2 = "V"
    case "W to X"
    Query1 = "SELECT * FROM parks WHERE Name LIKE 'W%'"
    Query2 = "SELECT * FROM parks WHERE Name LIKE 'X%'"
    index1 = "W"
    index2 = "X"
    case "Y to Z"
    Query1 = "SELECT * FROM parks WHERE Name LIKE 'Y%'"
    Query2 = "SELECT * FROM parks WHERE Name LIKE 'Z%'"
    index1 = "Y"
    index2 = "Z"
    End Select
    %>





    <tr>
    <td colspan="2" align="left" valign="top"> <table width="100%" border="0"
    align="center" cellpadding="4" cellspacing="4">
    <tr align="center">
    <td><font color="990000" size="3" face="Arial, Helvetica,
    sans-serif"><strong><%=index1%></strong></font></td>
    <td><div align="center"><font size="3"><strong><font color="990000"
    face="Arial, Helvetica,
    sans-serif"><%=index2%></font></strong></font></div></td>
    </tr>
    <tr align="left" valign="top">
    <td><font color="#9966FF" size="1" face="Arial, Helvetica, sans-serif">

    <%
    OnMenu.Open Query1, Connect, adOpenStatic, adLockOptimistic
    do while Onmenu.EOF = False

    Response.Write("<a href='parks_details.asp?SchEdit=True&WhichId=")
    Response.Write(Onmenu("park_id"))
    Response.Write("'>")
    Response.Write("<font face='Verdana' size='1' >" + OnMenu("Name"))
    Response.Write("</a>")
    Response.Write("<br>")

    OnMenu.MoveNext
    loop

    %>
    <br>
    <br>

    </font></td>
    <td><font color="#9966FF" size="1" face="Arial, Helvetica, sans-serif">
    <%
    OnMenu2.Open Query2, Connect, adOpenStatic, adLockOptimistic
    do while Onmenu2.EOF = False

    Response.Write("<a href='parks_details.asp?SchEdit=True&WhichId=")
    Response.Write(Onmenu2("park_id"))
    Response.Write("'>")
    Response.Write("<font face='Verdana' size='1' >" + OnMenu2("Name"))
    Response.Write("</a>")
    Response.Write("<br>")

    OnMenu2.MoveNext
    loop

    %>
    <br>
    <br>

    </font></td>
    </tr>


    What I want to know, is what is the best way to go about doing this with
    Coldfusion?


    Thanks-
    CHuck


    ChuckRWD Guest

  2. #2

    Default Re: Two Menu-Type Form on one page!

    There are much simpler ways of doing this than having to check 13 cases and
    then running 2 queries to display your output. Basically you need to get the 2
    letters from your form that you want to use to query your database. Your select
    can look something like this:

    <SELECT NAME="letters">
    <OPTION VALUE="A,B">A to B</OPTION>
    <OPTION VALUE="C,D">C to D</OPTION>
    <OPTION VALUE="E,F">E to F</OPTION>

    and so on. When your form is submitted you'll have Form.letters with a string
    like "A,B".

    For your SQL, you can use the Left function to select on the first letter of
    the name, and IN to match a set of values. So you'd want something like this:

    WHERE left(name,1) IN ('C','D')

    To get to this from your query, you use the functions ListQualify to add
    single quotes to the letters, and PreserveSingleQuotes to keep these quotes in
    your query. See the attached code.

    For your output, if you group on the first letter you can place individual
    headings on different parts of your list.

    The whole thing should take 5 or 6 lines of code, instead of the 100 you have
    now.

    -Paul



    <CFSET letters = ListQualify(Form.letters, "'")>

    <CFQUERY NAME="getName" DATASOURCE="mydata">
    SELECT name, field2, left(name,1) AS firstletter FROM parks
    WHERE left(name,1) IN (#PreserveSingleQuotes(letters)#) ORDER BY name
    </CFQUERY>

    <CFOUTPUT QUERY="getName" GROUP="firstletter">
    <H3>#firstletter#</H3>
    <CFOUTPUT>#name#<BR></CFOUTPUT>
    </CFOUTPUT>

    dempster Guest

  3. #3

    Default Re: Two Menu-Type Form on one page!

    In addition to dempster's answer, on your form, you may wish to display only
    those letters which matter. Something like this:

    <cfquery name="letters">
    select distinct substr(name, 1,1) firstletter from parks
    </cfquery>
    <cfform>
    <cfoutput query="letters">
    <cfinput name="letters" value="#firstletter#" type="checkbox">#firstletter#
    </cfoutput>

    Then, check to see if any boxes were checked (isdefined(form.letters") and
    carry on.

    Dan Guest

Similar Threads

  1. List/Menu Form hides dropdown Menu
    By Lerbekmo in forum Macromedia Dynamic HTML
    Replies: 1
    Last Post: January 5th, 10:56 PM
  2. only dos type menu avail?
    By socal.penguin@gmail.com in forum MySQL
    Replies: 2
    Last Post: December 23rd, 12:04 AM
  3. JavaScript for menu bars or side menu for an externalweb page
    By cJeffreywang in forum Macromedia Dynamic HTML
    Replies: 3
    Last Post: January 11th, 01:52 AM
  4. Type Face menu
    By andrew in forum Adobe Illustrator Macintosh
    Replies: 2
    Last Post: August 2nd, 09:11 PM
  5. Menu type in Fireworks
    By KinŽsole in forum Macromedia Fireworks
    Replies: 0
    Last Post: September 24th, 04:43 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139