Skip to main content
Inspiring
June 16, 2008
Answered

coldfusion problem - help please

  • June 16, 2008
  • 7 replies
  • 650 views
I am trying to do a database query to pull information about US state codes (TN, GA, AL, etc.) and in my search I have a dropdown that will let you select whichever state you want to search and based upon the state it gives it it's specific code and uses it to cross-reference with the database and so forth. I want to put in an "All" or "Any" into the states and when they select it, it just uses all of the state codes instead of one specific one. Any ideas on how I can get this to work?

Do I need to try some type of if,else statement or is there any way to say in the code that when the user selects that then just use all of the codes together. I'm a little new at this so any help will be much appreciated. I can put snippets of the code that I am using if needed.
    This topic has been closed for replies.
    Correct answer j_williford
    As ironic as this all is, I have actually figured it out. I apologize that I put you guys through all this and I didn't get too much feedback from you all but I think the if/else statements helped me a little. I actually had some more query code on my page with the Google map and I needed to change it around with the "state" statement. It works just like I dreamed it now. To be honest I don't really know if I did everything correct, as I said I'm pretty new at this, but as long as it works and everything is fine, then I think I will be good to go. Thanks again everybody and maybe I'll need your help again down the road.

    7 replies

    Inspiring
    June 16, 2008
    j.williford,

    I know I was not much help here. But it is good to hear you figured it out :) If you think the final code snippet will help someone down the road, feel free to post it.

    Inspiring
    June 16, 2008
    Yes, I think I understand what you are trying to achieve. But, I am not very familiar with Google Maps. Exactly what piece do you need to adjust to get the desired results: one of the queries or the map URL?

    Originally, it sounded as if you needed to modify one of the queries. But I am starting to suspect you just want to adjust the URL. Example, when "All" is selected, omit the "state", "lat" and "lon" parameters. But as I said, that is just a guess ..
    j_willifordAuthorCorrect answer
    Inspiring
    June 16, 2008
    As ironic as this all is, I have actually figured it out. I apologize that I put you guys through all this and I didn't get too much feedback from you all but I think the if/else statements helped me a little. I actually had some more query code on my page with the Google map and I needed to change it around with the "state" statement. It works just like I dreamed it now. To be honest I don't really know if I did everything correct, as I said I'm pretty new at this, but as long as it works and everything is fine, then I think I will be good to go. Thanks again everybody and maybe I'll need your help again down the road.
    Inspiring
    June 16, 2008
    j.williford,

    Yes, once I saw the second post I realized your goal was different than what I originally thought.

    But I am not sure I completely understand the results of the current code. Can you explain it in terms of what the code/queries are doing now (ie wrong) versus how you would like it to behave?

    Inspiring
    June 16, 2008
    The code is supposed to create search with a dropdown where users can select a state and also (if they wanted) be able to put some or all of the name of a property that they are searching for and when they click submit, an iframe will pull in a Google map on the left hand side of the page with their search results. Before they search, the left hand side will just have text hence why the "select one" would be a value of none so the map wouldn't show up. It's kind of redundant to have a map with nothing on it and it not do anything but sit there.

    If you search for just part of a name of a property and no state, there are search results that show up underneath the search fields (I left out that code but you guys don't really need it) but no map shows up because I haven't been able to say that all of the state codes should be selected in the query when the search value of the state is set to "all" or "any". This is where I am stuck. I want to show all possible properties and their bubbles on the map but I haven't been able to do it with different variations of if/else statements that I have tried.
    Inspiring
    June 16, 2008
    > but no map shows up because I haven't been able to say that all of the state codes
    > should be selected in the query when the search value of the state is set to "all" or "any".

    So if _either_ "none" or "all" is selected, you want to include all state codes? Which query are you trying to tweak, the first or the second one?
    Inspiring
    June 16, 2008
    j.williford,

    Oops. I was responding to your original question. I did not see the previous replies before responding ;-)
    Inspiring
    June 16, 2008
    no problem -==cfSearching==-,

    I understand where you're coming from but if you can see from the code that I gave I can't exactly make "all" or an empty string as the default. I need a page of text to show up for the search feature and the "select one" to be displayed and they are both equal to "none" if I did all, it would look awkward and have a bunch of bubbles all over a Google map and its not too pretty (I've seen it before). Like I said earlier, this isn't exactly a situation where I will just die if I don't have it but it would still be pretty neat to be able to have it. I understand from as little logic as I have in ColdFusion and from other posts that this will need to be an if/else statement but I'm really trying to figure out if there is just a quick way to say "all" equals all of the state codes.
    Inspiring
    June 16, 2008
    set the value of the ALL option to 'showall' or something like that,
    which can;t be the value of a state.

    change your query that selects states based on user selection to:
    SELECT ...
    FROM ...
    <cfif form.name_of_select_control eq 'selectall'>
    ORDER BY sate_column, etc
    <cfelse>
    WHERE state_column = <cfqueryparam cfsqltype="cf_sql_varchar"
    value="#form.name_of_select_control#">
    ORDER BY etc
    </cfif>

    i hope you are also checking that at least one state or ALL was selected...


    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    Known Participant
    June 16, 2008
    Or another option would be to have the if / else separate

    <cfif form.stateCode eq "All">
    <cfset where = "">
    <cfelse>
    <cfset where = "WHERE stateCode = #form.stateCode">
    </cfif>

    Then a single query:
    SELECT * FROM states #where# ORDER BY stateName

    This would give a query either

    SELECT * FROM states ORDER BY stateName - if all was selected - otherwise -
    SELECT * FROM states WHERE stateCode = #form.stateCode# ORDER BY stateName

    But this method could cause problems with query orders or general confusion

    Michael
    Inspiring
    June 16, 2008
    I am actually doing a Google Map search on my website and need it to not only show the map but also properties that are associated with those states. I will attach all of the code that I have so far for this project. I don't really know if it is necessary that I have this work where I can show all of the states at one time but it would really be useful.
    Known Participant
    June 16, 2008
    The most basic way would be to use if / else and two separate queries