Hi all
The cfif doesn't appear to be working, if I add sectorid=1 to the url it works but throws an error if there is no value. Why is this not working? Thank you
<cfquery name="qNames" datasource="sales">
select * from COMPANY, sector
where COMPANY.sectorid = sector.sectorid
<cFIF IsDefined(url.sectorID)>
and sector.sectorid = #url.sectorid#
</cfif>
</cfquery>
You're not using isDefined() properly.
Read the docs:
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461 172e0811cbec22c24-7fbd.html
And pay close attention to the example code.
Also: you're better off using structKeyExists() than isDefined(): isDefined() is flaky sometimes, and is kind of a hangover from older versions of CF.
--
Adam
Hi thanks for the replies I used structKeyExists as per lyndon's recommendation, but the page throws an error if there is page.cfm without any sectorid parameter
<cfinclude template = "header.cfm">
<cfquery name="qNames" datasource="sales">
select * from COMPANY, sector
where COMPANY.sectorid = sector.sectorid
<cfif structKeyExists(url,"sectorID")>
and sector.sectorid = #url.sectorid#
</cfif>
</cfquery>
<cfquery name="sNames" datasource="sales">
select * from COMPANY, sector
where <cFIF IsDefined('url.sectorID')>
sector.sectorid = #url.sectorid#
</cfif>
</cfquery>
<CFQUERY name="sector" datasource="sales">
SELECT sectorId, sector
FROM sector
ORDER BY sector
</CFQUERY>
but the page throws an error if there is page.cfm without any sectorid parameter
If you ever get an error you want help with, don't just tell us you got an error, tell us what the error is. Inded paying close attention to the error message will generally tell you where you're going wrong.
Also, look at this:
<cfquery name="sNames" datasource="sales">
select * from COMPANY, sector
where <cFIF IsDefined('url.sectorID')>
sector.sectorid = #url.sectorid#
</cfif>
</cfquery>
If there is no sectorid, what SQL will that create?
The SQL being sent to the DB should be part of the error message, btw...
--
Adam
North America
Europe, Middle East and Africa
Asia Pacific