Skip to main content
Inspiring
August 9, 2011
Question

cfif url.

  • August 9, 2011
  • 1 reply
  • 903 views

i have a dynamic spry link that displays only cities of a record. depending on the city one chooses, the resulting hyperlink page will display the product contents from that city. when i do this, the action page throw an error and my "communities" query does not showup in the binding tab. i would like to use just one action page to display the information from the city that was chosen, and not have to make multiple pages for each city.

Question: How can a text hyperlink be integrated in a CFIF statement? It works well with a variable and html, but i'm kinda stuck.

Here is the syntax that i'm using. First i will display the first page to where the link will be chosen from, then the action page's syntax:

FIRST PAGE

<cfquery name="Places_City" datasource="properties">
SELECT community.comid, community.comcity
FROM community
GROUP BY community.comcity
ORDER BY community.comcity desc
</cfquery>

<li><a href="#">Our Places</a>
    <ul><cfoutput query="places_city"><li><a href="community_places.cfm" id="places">#Places_City.comcity#</a></li></cfoutput>
     
    </ul>

ACTION PAGE

<cfif isdefined('url.PLACES') is "St. George">
<cfquery name="community" datasource="properties">    
SELECT community.*, unit.*
FROM community, unit
WHERE 0=0
AND unit.unicomid = community.comid
AND community.comcity= 'St. George'
</cfquery>

<cfelseif isdefined('url.PLACES') is "Salt lake city">
<cfquery name="community" datasource="properties">
SELECT community.*, unit.*
FROM community, unit
WHERE 0=0
AND unit.unicomid = community.comid
AND community.comcity= 'Salt lake city'
</cfquery></cfif>

    This topic has been closed for replies.

    1 reply

    Inspiring
    August 9, 2011

    IsDefined() returns either true or false.  It does not return the value of the variable you are checking.

    From a logic perspective, checking for the existance of a url variable is a good idea.  However, once you know it's there, you can use it's value in your query, meaning that you only have to type it out once.

    Inspiring
    August 9, 2011

    I guessing that my action page should read:

    ACTION PAGE

    <cfif  #url.PLACES# is "St. George">
    <cfquery name="community" datasource="properties">    
    SELECT community.*, unit.*
    FROM community, unit
    WHERE 0=0
    AND unit.unicomid = community.comid
    AND community.comcity= 'St. George'
    </cfquery>

    <cfelseif #url.PLACES#  is "Salt lake city">
    <cfquery name="community" datasource="properties">
    SELECT community.*, unit.*
    FROM community, unit
    WHERE 0=0
    AND unit.unicomid = community.comid
    AND community.comcity= 'Salt lake city'
    </cfquery></cfif>

    Inspiring
    August 9, 2011

    Too much code and too much conditional logic.  All you need it this:

    AND community.comcity= '#url.places#'

    You have some other issues as well.  cfqueryparam will solve some of them.