Solved

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

Posted on 2014-11-03
11
118 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
[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
  • 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
Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

 
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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

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

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

690 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