Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with CFIF Please.

Status
Not open for further replies.

ausi

Technical User
Joined
May 31, 2002
Messages
3
Location
US
Hi All,
First off I am new to this CF stuff so please take it easy on me:-) I have links on one page with price ranges in the URL like.
$0 to 100000 (min&max)
$100000 to 200000 and so on. What I am trying to do is make it so when someone clicks on one of these links and their are no products to display for that price range they will recieve a message. I am trying to do this with the CFIF tags with no luck. If their are no records to display I am assuming the #price# will be 0 thus display the message. I really confused about this CFIF stuff. Please help. Below is my code. Thank You!

<CFPARAM name=&quot;URL.min&quot; Type= &quot;any&quot;>
<CFPARAM name=&quot;URL.max&quot; Type= &quot;any&quot;>
<!--- Defined --->
<!--- Start Query --->
<cfquery name=&quot;getall_res&quot;
datasource=&quot;whatever&quot;
dbtype=&quot;ODBC&quot;>
SELECT ID, ref_number, smpic, address, city, short_description, price
FROM Listings
WHERE catagory = 'City'
AND price >= #URL.min#
AND price <= #URL.max#
ORDER BY price
</cfquery>
<!--- End Query --->
<html>
<head>
<cfinclude template=&quot;MainHeader.txt&quot;>
<table width=&quot;520&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; height=&quot;100%&quot;>
<cfif isdefined (&quot;URL.min&quot;)>
<cfif isdefined (&quot;URL.max&quot;)>
<cfif URL.min EQ &quot;0&quot;>
<cfelseif URL.max LT &quot;1&quot;>
<cfelse>
Sorry no products in this price range.
</cfif>
</cfif>
</cfif>

<!--- Start Output --->
<cfoutput query=&quot;getall_res&quot;>
<tr>
<td height=&quot;123&quot; valign=&quot;top&quot; colspan=&quot;2&quot;><a href=&quot;ResAllChild.cfm?smpic=#ID#&quot;><img src=&quot;listings/#smpic#.jpg&quot; border=&quot;0&quot; align=&quot;left&quot;></a>Number:
#ref_number#<br>
Address: #address#<br>
City: #city#<br>
#short_description# <br>
<b><font color=&quot;##FF0000&quot;>$#DecimalFormat(price)#</font></b> </td>
</tr>
<tr>
<td width=&quot;1&quot; height=&quot;21&quot;></td>
<td valign=&quot;middle&quot; width=&quot;520&quot; align=&quot;center&quot;><img src=&quot;images/Topline.gif&quot; width=&quot;505&quot; height=&quot;1&quot;></td>
</tr>
</cfoutput>
<!--- End Output --->

</table>
<cfinclude template=&quot;MainFooter.txt&quot;>
</body>
</html>
 
when you use multiple cfif statements:

WHERE catagory = 'City'
<cfif URL.min NEQ &quot;any&quot;>
AND price >= #URL.min#
</cfif>
<cfif URL.max NEQ &quot;any&quot;>
AND price <= #URL.max#
</cfif>

if URL.min NEQ &quot;any&quot; and if URL.max NEQ &quot;any&quot; , both constraints (AND price >= #URL.min#, AND price <= #URL.max#) will be processed;

if you use else if condition:

WHERE catagory = 'City'
<cfif URL.min NEQ &quot;any&quot;>
AND price >= #URL.min#
<cfelseif URL.max NEQ &quot;any&quot;>
AND price <= #URL.max#
</cfif>

only ONE will be processed - the first if statement that resturn true;

whit that in mind:
<cfif isdefined (&quot;URL.min&quot;)>
//this if statement will be executed only if URL.min is defined, otherwise, it will never pass first condition and will never get the chance to examine URL.max
<cfif isdefined (&quot;URL.max&quot;)>
<cfif URL.min EQ &quot;0&quot;>
<cfelseif URL.max LT &quot;1&quot;>
<cfelse>
Sorry no products in this price range.
</cfif>
</cfif>
</cfif>

you can change that to:

<cfif isdefined (&quot;URL.min&quot;) OR isdefined (&quot;URL.max&quot;)>
<cfif URL.min EQ &quot;0&quot;>
<!-- query output -->
<cfelseif URL.max LT &quot;1&quot;>
<!-- query output -->
<cfelse>
Sorry no products in this price range.
</cfif>
</cfif>

hope this help you

Sylvano
dsylvano@hotmail.com
 
Fisrt, you may want to change your queries to use the BETWEEN. but that isn't what you are asking about.

You have to get a number of query results to determine if there are any matches or not.

<cfquery name=&quot;getALL&quot;...>
Select ......
WHER...
</cfquery>

This is the IF part...

<cfif getALL.recordcount eq 0>
<!--- put a message --->
I'm sorry, there are not results
<cfelse>
<!--- if there is results --->
show them here...
</cfif>

This is just on very simple way to do it.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top