Solved

CF - Problem with cfswitch

Posted on 2009-07-02
11
412 Views
Last Modified: 2013-12-16
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

0
Comment
Question by:JohnMac328
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 10

Expert Comment

by:js_vaughan
ID: 24767777
<cfcase value="5;7">

By default, shouldn't you be using a comma instead?
0
 

Author Comment

by:JohnMac328
ID: 24767807
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?
0
 

Author Comment

by:JohnMac328
ID: 24767957
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.
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 10

Expert Comment

by:js_vaughan
ID: 24768023
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?
0
 

Author Comment

by:JohnMac328
ID: 24768062
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

0
 
LVL 10

Expert Comment

by:js_vaughan
ID: 24768132
You need to put that entire CFSWITCH block inside this tag :

<cfoutput query="getAllFilms"> ... </cfoutput>
0
 

Author Comment

by:JohnMac328
ID: 24768142
I just said that and you said no.  When I do that it blows up the table display
0
 
LVL 10

Expert Comment

by:js_vaughan
ID: 24768180
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?
0
 
LVL 10

Accepted Solution

by:
js_vaughan earned 500 total points
ID: 24768229
Quick FYI :

I copy/pasted all of your code, only replacing your query with "fake" query results so i could test locally - and it runs beautiful.  Below is a copy of the code I tested.
<html>
<head>
<title>CFSWITCH</title>
</head>
 
<body>
<cfset getAllFilms = queryNew("VideoID, Video_Name, Length, Production_Company, Category_Name, Availability, credits, Category_ID")>
<cfset QueryAddRow(getAllFilms)>
<cfset QuerySetCell(getAllFilms, "VideoID", 1)>
<cfset QuerySetCell(getAllFilms, "Video_Name", 1)>
<cfset QuerySetCell(getAllFilms, "Length", 1)>
<cfset QuerySetCell(getAllFilms, "Production_Company", 1)>
<cfset QuerySetCell(getAllFilms, "Category_Name", 1)>
<cfset QuerySetCell(getAllFilms, "Availability", 1)>
<cfset QuerySetCell(getAllFilms, "credits", 1)>
<cfset QuerySetCell(getAllFilms, "Category_ID", 1)>
<cfset QueryAddRow(getAllFilms)>
<cfset QuerySetCell(getAllFilms, "VideoID", 2)>
<cfset QuerySetCell(getAllFilms, "Video_Name", 2)>
<cfset QuerySetCell(getAllFilms, "Length", 2)>
<cfset QuerySetCell(getAllFilms, "Production_Company", 2)>
<cfset QuerySetCell(getAllFilms, "Category_Name", 2)>
<cfset QuerySetCell(getAllFilms, "Availability", 2)>
<cfset QuerySetCell(getAllFilms, "credits", 2)>
<cfset QuerySetCell(getAllFilms, "Category_ID", 2)>
<cfset QueryAddRow(getAllFilms)>
<cfset QuerySetCell(getAllFilms, "VideoID", 3)>
<cfset QuerySetCell(getAllFilms, "Video_Name", 3)>
<cfset QuerySetCell(getAllFilms, "Length", 3)>
<cfset QuerySetCell(getAllFilms, "Production_Company", 3)>
<cfset QuerySetCell(getAllFilms, "Category_Name", 3)>
<cfset QuerySetCell(getAllFilms, "Availability", 3)>
<cfset QuerySetCell(getAllFilms, "credits", 3)>
<cfset QuerySetCell(getAllFilms, "Category_ID", 3)>
 
<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">
 
<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>
     
 <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

0
 

Author Closing Comment

by:JohnMac328
ID: 31599363
Well before it caused the table cells to go nuts but I copied yours and it worked fine.  Thanks for all the help
0
 
LVL 10

Expert Comment

by:js_vaughan
ID: 24768257
Glad to help :-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this short web based tutorial, I wanted to show users how they can still use the powers of FrontPage in conjunction with Expression Web 3.  Even though Microsoft eliminated the use of Web components, we can still use them with FrontPage and edit …
When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question