Headers
HeaderID (PK)
Header
SubHeaders
SubHeaderID (PK)
HeaderID (FK)
SubHeader
Titles
TitleID (PK)
SubHeaderID (FK)
Title
Query them:
<cfquery name="getHeadings" datasource="test">
SELECT H.HeaderID, H.Header, S.SubHeaderID, S.SubHeader, T.Title
FROM Headers H, SubHeaders S, Titles T
WHERE H.HeaderID = S.HeaderID
AND S.SubHeaderID = T.SubHeaderID
ORDER BY H.HeaderID, S.SubHeaderID
</cfquery>
And then use grouped output (the order by in the query is very
important):
<cfoutput query="getHeadings" group="HeaderID">
<h1>#getHeadings.Header#</h1>
<cfoutput group="SubHeaderID">
<h2>#getHeadings.SubHeader#</h2>
<cfoutput>
<h3>#getHeadings.Title#</h3>
</cfoutput>
</cfoutput>
</cfoutput>
> -----Original Message-----
> From: Ben Densmore [mailto:[EMAIL PROTECTED]
> Sent: maandag 19 januari 2004 21:54
> To: CF-Talk
> Subject: SOT: DB Design Question
>
> I am building a few new tables to store some articles and
> notes on our website. I want it structured so that it displays:
>
> Top Level Header
> Sub Heading
> Title of Article
>
> I built 3 separate tables:
> One has just an ID and a Header field
> The second has an ID and the Sub Heading The third table
> has an ID, the Header Foreign Key and the SubHeading Foreign
> key and then the title and where the file is stored.
>
> The problem I'm having is when I do my query:
> <cfquery name="getHeadings" datasource="test"> Select
> appNotesHeaders.*,AppHeadings.*,appNotes.*
> from appNotesHeaders,AppHeadings,appNotes
> where
> AppNotes.HeaderFK = appNotesHeaders.appNotesHeadersID And
> AppNotes.HeadingFK = AppHeadings.App_Heading_ID </cfquery>
>
> It displays my Headers and Sub Headings more than once if
> there is more than one article in a given Header.
>
> So right now I have a total of 3 Headers, I have multiple Sub
> Headings that can be under one header and multiple titles
> under each heading.
>
> So the output should look like:
>
> Application Notes
> General Application Notes
> Title 1
> Title 2
> Title 3
>
> Amplifier Application Notes
> Title 1
> Title 2
> Title 3
>
> Articles
> Featured Articles
> Title 1
> Title 2
> Title 3
>
> But right now I am getting:
>
> Application Notes
> General Application Notes
> Title 1
> Application Notes
> Title 2
>
> Am I totally losing it and not designing the DB right? I have
> built way more complex databases than this but yet I'm
> struggling to see my mistake here.
>
> Thanks,
> Ben
>
>
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

