Solved

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

Posted on 2014-11-03
11
113 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now