ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 6th, 2005, 04:24 PM
bleutuna bleutuna is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 1 bleutuna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 57 sec
Reputation Power: 0
Joining more than two tables on same ID

I have a table (films) that has an ID assigned to it when you create it with a form.

Then, I update multiple tables with information from the form, and populate a field in each table called filmID with the ID assigned in the films table.

So now, I want to pull ALL recordsets from ALL tables where filmID = an ID passed via a URL.

In other words, you'd click the name of the film, which has an assigned ID, then that'd take you to a page where you could see all the other information that's assocated with it.

I figured this'd be the best way to set up my tables, since they all the records I'd want would have the same filmID.

And I've written code that DOES pull the information. only problem is, if it comes to a table that doesn't have information (because, say, there wasn't a costume designer on that film or a script supervisor, so the filmID was never updated and no record was ever created), the page breaks.

Instead of showing me the results of the ones DO have records, it shows me an absolutely blank page, with nothing in the source code.

Here's the code I'm using:


Code:

<cfparam name="introMsg" default="View Film Details">
<cfparam name="passedID" default="">

<cfset passedID = #URL.filmID#>

<cfif passedID IS NOT "">
	<cfquery name="pullFilmInfo" datasource="#Request.MainDSN#">
		SELECT 
			writerID,
			actorID,
			directorID,
			animatorID,
			artID,
			castingID,
			cinetogID,
			costumeID,
			crewID,
			decID,
			designerID,
			editorID,
			effectsID, 
			film.id,
			gafferID,
			gripID,
			makeupID,
			musicID,
			producerID,
			scriptID,
			soundID,
			titleID
		FROM
			writers,
			actors,
			directors,
			animators,
			art,
			casting,
			cinetog,
			costume,
			crew,
			dec,
			designers,
			editors,
			effects,
			films,
			gaffers,
			grips,
			makeup,
			music,
			producers,
			script,
			sound,
			titles
		WHERE
			writers.filmID = #passedID# AND
			actors.filmID = #passedID# AND
			directors.filmID = #passedID# AND
			animators.filmID = #passedID# AND			
			art.filmID = #passedID# AND						
			casting.filmID = #passedID# AND						
			cinetog.filmID = #passedID# AND						
			costume.filmID = #passedID# AND						
			crew.filmID = #passedID# AND						
			designers.filmID = #passedID# AND						
			editors.filmID = #passedID# AND						
			effects.filmID = #passedID# AND						
			films.id = #passedID# AND						
			gaffers.filmID = #passedID# AND						
			grips.filmID = #passedID# AND						
			makeup.filmID = #passedID# AND						
			music.filmID = #passedID# AND						
			producers.filmID = #passedID# AND						
			script.filmID = #passedID# AND						
			sound.filmID = #passedID# AND						
			titles.filmID = #passedID#	
	</cfquery>
</cfif>

<cfif "#pullFilmInfo.writerID#" IS NOT "">
	<cfoutput>#pullFilmInfo.writerID#</cfoutput>
</cfif>

<cfif "#pullFilmInfo.actorID#" IS NOT "">
	<cfoutput>#pullFilmInfo.actorID#</cfoutput>
</cfif>

<cfif "#pullFilmInfo.directorID#" IS NOT "">
	<cfoutput>#pullFilmInfo.directorID#</cfoutput>
</cfif>


If I remove ALL REFERENCES to tables I know don't have a matching recordset in them, the code works fine. But as soon as I put ONE back in there that's empty - boom....BLANK PAGE!

Now, I'm new to CF, and so, this could be my problem. Unfortunately, 6 hours now looking on the web for a fix has been completely difficult.

Probably I should be using JOIN or INNER JOIN rather than the AND on the WHERE part of my SQL statement.

But i've had NO luck finding any examples of this...especially with more than two tables being joined.

Help if you can


Reply With Quote
  #2  
Old August 8th, 2005, 03:17 PM
Bastion Bastion is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 181 Bastion User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 4 h 25 m 11 sec
Reputation Power: 5
I'm not completely sure what you are trying to do, but try looking at this article on outer joins to see if it helps any:

http://www.devx.com/dbzone/Article/17403/0/page/4

The text between <cfquery></cfquery> is SQL and if you can't find good examples for what you need in ColdFusion sites/books, try SQL-related sites/books.

And to do a join on multiple tables, you use parenthesis.

Code:
Select table1.ID, table1.itemTitle
FROM (table1 LEFT OUTER JOIN table2 ON table1.catID = table2.ID) LEFT OUTER JOIN table 3 ON table1.eventID = table3.ID


Or however that code goes.

Reply With Quote
  #3  
Old August 8th, 2005, 06:28 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,682 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 15 h 42 m 54 sec
Reputation Power: 53
Yes, what you are looking for is an outer join.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Joining more than two tables on same ID


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT