Solved

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

Posted on 2014-11-03
11
117 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 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