Link to home
Start Free TrialLog in
Avatar of JohnMac328
JohnMac328Flag for United States of America

asked on

CF - Problem with cfswitch

I am getting a error when I try to run a cf switch, does it have to be inside the </cfoutput>?
When I try that it screws up the table display.

Here is the error, the first </cfcase> is where it is bombing.

Invalid CFML construct found on line 19 at column 1.  
ColdFusion was looking at the following text:
</

 
Thanks,
<cfswitch expression="#CategoryID#">
<cfcase value="1">
<cfset color= "blue"
</cfcase>
<cfcase value="5;7">
<cfset color= "black"
</cfcase>
<cfcase value="2">
<cfset color= "red"
</cfcase>
<cfcase value="3">
<cfset color= "purple"
</cfcase>
<cfcase value="4">
<cfset color= "green"
</cfcase>
</cfswitch>
 
   <td width="191" bgcolor="#color#">#Category_Name#</td>

Open in new window

Avatar of js_vaughan
js_vaughan

<cfcase value="5;7">

By default, shouldn't you be using a comma instead?
Avatar of JohnMac328

ASKER

I caught it, I didn't have brackets on some.  Now I get

Variable CATEGORY_ID is undefined.

<cfswitch expression="#Category_ID#">
<cfcase value="1">
<cfset color= "blue">
</cfcase>
<cfcase value="5,7">
<cfset color= "black">
</cfcase>
<cfcase value="2">
<cfset color= "red">
</cfcase>
<cfcase value="3">
<cfset color= "purple">
</cfcase>
<cfcase value="4">
<cfset color= "green">
</cfcase>
</cfswitch>

That is the correct field name, what does it not like?
Oh wait, that takes me back to my original question.  Does it have to be inside the output query?  That makes my table fall apart.
No, it does not need to be inside a cfoutput.  Your code is perfectly valid.

I copy/pasted your code and it worked just fine.
<cfset Category_ID = "5"> above your code
<cfoutput>#color#</cfoutput> after your code

"black" was output on my screen.

The variable does not exist.  Aside from spelling mistakes, are you using CFLOCATION, a form, link, or any other type of redirect that may be causing the variable to disappear?
Here it is from top to bottom, I still can't see what is wrong
<cfquery name="getAllFilms" datasource="#datasource#">
   
SELECT VideoList.VideoID, VideoList.Video_Name, VideoList.Length, VideoList.Production_Company, Category.Category_Name, VideoList.Availability, VideoList.credits,Category.Category_ID
FROM Category INNER JOIN VideoList ON Category.Category_ID = VideoList.CategoryID WHERE VideoList.Availability <>2
order by VideoList.VideoID 
 
 </cfquery>
 
<cfswitch expression="#Category_ID#">
<cfcase value="1">
<cfset color= "blue">
</cfcase>
<cfcase value="5,7">
<cfset color= "black">
</cfcase>
<cfcase value="2">
<cfset color= "red">
</cfcase>
<cfcase value="3">
<cfset color= "purple">
</cfcase>
<cfcase value="4">
<cfset color= "green">
</cfcase>
</cfswitch>
 
<body>
 
<br />
<br />
<table width="1121" border="1">
 <tr class="DataGridHeader">
    <th width="69">ID</th>
     <th width="262">Video</th>
    <th width="128">Length</th>
    <th width="280">Company</th>
    <th width="193">Category</th>
    <th width="111">Credits</th>
    <th width="79">Availability</th>
   </tr> 
     <tr>   <cfoutput query="getAllFilms">
     
 <tr class="tablerowdata">
    <td  width="89">#VideoID#</td>
    <td width="242">#Video_Name#</td>
    <td width="129">#Length#&nbsp;mins</td>
    <td width="280">#Production_Company#</td>
    <td width="191" bgcolor="#color#">#Category_Name#</td>
    <td width="112"><div align="center">#Credits#</div></td>
   
    <td width="78"> <input type="text"  size="10" readonly="readonly" name="Availability" value="#iif(Availability EQ 1, de('Available'), de('Checked Out'))#" ></td>
  </tr>
   </cfoutput>
</table>
 
</body>
</html>

Open in new window

You need to put that entire CFSWITCH block inside this tag :

<cfoutput query="getAllFilms"> ... </cfoutput>
I just said that and you said no.  When I do that it blows up the table display
I said no because i assumed the variable was created with a simple <cfset>, you did not specify it came from a query.

As for blowing up the table display, I'm not sure I follow exactly.  How does it blow it up?
ASKER CERTIFIED SOLUTION
Avatar of js_vaughan
js_vaughan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well before it caused the table cells to go nuts but I copied yours and it worked fine.  Thanks for all the help
Glad to help :-)