Reputation: 4055
I am having an issue with the sytnax on how to get a value from a database and then check that value in an if statement in ColdFusion
This is what I have so far:
<cfquery name="reserveCheck" datasource="RC">
SELECT comp_type FROM partnerCompany WHERE comp_ID = "#COOKIE.RISOURCEUSRID#"
</cfquery>
<cfoutput>
<cfif #reserveCheck# NEQ 4>
<li><a href="http://mywebsite/gonow/index.cfm" title="Product Search" target="_blank">Product Search</a></li>
</cfif>
</cfoutput>
Upvotes: 0
Views: 1197
Reputation: 41
You could modify your query so that it is not selected in the first place. Change your query to
<cfquery name="reserveCheck" datasource="RC">
SELECT comp_type FROM partnerCompany
WHERE comp_ID = "#COOKIE.RISOURCEUSRID#"
AND comp_type <> 4
</cfquery>
Upvotes: 0
Reputation: 20804
Change this:
<cfif #reserveCheck# NEQ 4>
to this
<cfif reserveCheck.comp_type NEQ 4>
This assumes your query only returns one row. If the query returns more than one row, the code in this answer only looks at the first row. That may or may not be what you want.
Upvotes: 1