Solved

<cfoutput>#getBureauProjects.bureauTitle#</cfoutput> does not display bureauTitle

Posted on 2014-11-03
11
116 Views
Last Modified: 2014-11-03
ColdFusion 9

I have been staring at this for two hours. I could use some advice.

On this page: http://www.doivista.org/showBureauRecord.cfm?bureauID=9

I use <h2><cfoutput>#getBureauProjects.bureauTitle#</cfoutput> Projects, by State</h2> to display bureauTitle ... except the bureauTitle does not display.

Note: when a bureau has projects associated with it, the bureauTitle will display. If no projects, then ... no bureauTitle.

But I don't see the logic of that in the code.

Here are the query and the HTML. I am sure I am missing something quite obvious that I would see if I ever got more than five hours of sleep per night. =) Thanks for your help.

Query:

<cfquery name="getBureauProjects" datasource="#application.datasource#">
SELECT
b.bureauID,
b.bureauTitle,
p.projectID,
p.ProjectName,
p.bureauTitle,
p.State,
p.Archive
FROM #REQUEST.BureauTable# b
INNER JOIN #REQUEST.ProjectsTable# p
ON p.bureauTitle = b.bureauTitle
WHERE b.bureauID = <cfqueryparam cfsqltype="cf_sql_integer" value="#val(url.bureauID)#">
AND p.Archive = <cfqueryparam value="0" cfsqltype="cf_sql_bit">
ORDER BY p.State ASC
</cfquery>

Open in new window


HTML:

<h1><cfoutput>#REQUEST.companyName#</cfoutput> Projects</h1>


<h2><cfoutput>#getBureauProjects.bureauTitle#</cfoutput> Projects, by State</h2>


<cfif getBureauProjects.recordcount GT 0>

<cfoutput query="getBureauProjects" group="state">
<h3>#getBureauProjects.State#</h3>
<p><a href="/showProjectRecord.cfm?ProjectID=#val(getBureauProjects.ProjectID)#">#getBureauProjects.ProjectName#</a></p>
</cfoutput>

<cfelse>
<h2>Currently no projects are associated with this bureau. Please check back for future projects.</h2>

</cfif>

Open in new window

0
Comment
Question by:Eric Bourland
  • 4
  • 4
  • 3
11 Comments
 
LVL 36

Assisted Solution

by:SidFishes
SidFishes earned 250 total points
ID: 40420203
Basic stuff but are you sure the query is returning data?

If there are no projects ("Currently no projects are associated...") you won't see a bureauTitle...
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 250 total points
ID: 40420207
EDIT: It's because the query uses an INNER JOIN. It only returns the title (and other fields) if there's one or more matching projects. As Sid pointed out, when there are no projects - the query will be empty. That's why you don't see the title.

If you always want to return the bureau title - even when there are no projects - use a LEFT JOIN.

<cfquery name="getBureauProjects" datasource="#application.datasource#">
SELECT
b.bureauID,
b.bureauTitle,
p.projectID,
p.ProjectName,
p.bureauTitle,
p.State,
p.Archive
FROM #REQUEST.BureauTable# b
            LEFT JOIN #REQUEST.ProjectsTable# p
            ON p.bureauTitle = b.bureauTitle
           <!--- no need for cfqueryparam when it's a hard coded value --->
           AND  p.Archive = 0
WHERE b.bureauID = <cfqueryparam cfsqltype="cf_sql_integer" value="#val(url.bureauID)#">
ORDER BY p.State ASC

Open in new window


However, changing the JOIN type means the recordCount will always be GT 0. You'll also need to change the CFIF logic

<!--- if a project was found ...--->
<cfif getBureauProjects.projectID GT 0>

<cfoutput query="getBureauProjects" group="state">
<h3>#getBureauProjects.State#</h3>
<p><a href="/showProjectRecord.cfm?ProjectID=#val(getBureauProjects.ProjectID)#">#getBureauProjects.ProjectName#</a></p>
</cfoutput>

<cfelse>
<h2>Currently no projects are associated with this bureau. Please check back for future projects.</h2>

</cfif>

Open in new window

0
 
LVL 36

Expert Comment

by:SidFishes
ID: 40420211
see agx posted exactly what I said...except with all that detail and stuff to help you actually solve the problem... :)
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 52

Expert Comment

by:_agx_
ID: 40420220
I was so busy typing all that I didn't see your comment until after I posted :P  But once I did, I posted an "EDIT" to point that out ;-)
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40420221
Sid, good to hear from you. Yes, I see now: in this case, the query does not return data.

Is there a way I can adjust that query so that the bureauTitle will display even if no projects are associated with the bureau?

Thanks for your help. =)

E
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40420224
Got it now! Working on this. Thank you, _agx_ and Sid. More soon..... E
0
 
LVL 36

Assisted Solution

by:SidFishes
SidFishes earned 250 total points
ID: 40420235
Eric PLEASE make sure you don't give me any points.  agx's answer is undoubtedly all you need...
0
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 250 total points
ID: 40420257
No, he should because yours was the first response and it was right! You and GD always beat me out because I'm so overly wordy ;-)

Besides I am just teasing you because we both know we're not "those people" ie Ones that just repeat what was already said to get points.  Gotta love those folks ;-)
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40420268
You're both awesome. It's working great. I am smiling big ... solving these problems and understanding the solution is the most sensible and logical part of my day.
0
 
LVL 3

Author Closing Comment

by:Eric Bourland
ID: 40420279
Thank you _agx_ and Sid. Ummm. I'm just gonna divvy up points, and, if either of you (or GD) ever make it to DC, let me cook dinner for you.

Hope your day is going great. =) Take care.

Eric

p.s. I'm reviewing in my Forta book the differences in the various kinds of JOINs. Good to remember this.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40420402
Thanks Eric!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
COLD FUSION 6 27
recordcount is coming as undefined in query 4 62
Coldfusion - query to list question 3 36
Application.cfc - what is the order of events? 4 29
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

806 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