Professional Web Applications Themes

CFLOOP - Coldfusion Database Access

I need to display upcoming race infomration something like this: September Races =============== race location and date here race location and date here race location and date here October Races =============== race location and date here race location and date here race location and date here and so on for whatever months races are scheduled for. I have a table I need to pull all active codes from: <cfquery name="getVenues" datasource="#request.dsn#"> SELECT DISTINCT codes.desc, codes.ID FROM shows INNER JOIN codes ON races.locationCodeID = codes.ID WHERE codeActive = 'Y' Order By description </cfquery> I would then like to use the codes ...

Sponsored Links
  1. #1

    Default CFLOOP

    I need to display upcoming race infomration something like this:

    September Races
    ===============
    race location and date here
    race location and date here
    race location and date here

    October Races
    ===============
    race location and date here
    race location and date here
    race location and date here

    and so on for whatever months races are scheduled for.

    I have a table I need to pull all active codes from:

    <cfquery name="getVenues" datasource="#request.dsn#">
    SELECT DISTINCT codes.desc, codes.ID
    FROM shows INNER JOIN codes ON races.locationCodeID = codes.ID
    WHERE codeActive = 'Y'
    Order By description
    </cfquery>

    I would then like to use the codes that are returned from the above query to
    loop through another query and be able to group and sort by month and by
    location such as:
    < cfquery name="getRaces" datasource="#request.dsn#">
    SELECT * FROM races WHERE races.locationCodeID = codes.ID .........>
    </cfquery>

    I am not sure how to get each codes.ID and then run the above query. It does
    it for one codes.ID but does not loop. Any help is much appreciated.

    Sponsored Links
    cfuser7 Guest

  2. #2

    Default Re: CFLOOP

    Use a nested loop

    Loop through the months, and then inside that loop, loop through the locations/dates.
    tclaremont Guest

  3. #3

    Default Re: CFLOOP

    That does not help much. I know I need to loop, but how do I pull the results of the first query and use those as variables to run thought the second query? Or is that even what correct?
    cfuser7 Guest

  4. #4

    Default Re: CFLOOP

    Change your query so you are selecting specific fields. If your db supports
    it, also select the function that returns the month portion of the date. Then,
    you can do a simple cfoutput with query and group attributes. There is a good
    example of this in the cfml reference manual. If you don't have one, the
    internet does.

    Dan Guest

  5. #5

    Default Re: CFLOOP

    It sounds like what you really want to do is join your getVenues query with
    your
    getRaces query?

    If you re-write these two queries such that you have one SQL statement
    returning all the info in one resultset, I think you would be half-way where
    you
    want to be.

    The next step as suggested in the previous post is to use the cfoutput tag.
    ie. <cfoutput query="myQry" group="myMonthColumn">

    Livedocs has a very good example of this...
    http://livedocs.macromedia.com/coldfusion/7/htmldocs/00000309.htm


    Good luck!


    Guest

  6. #6

    Default Re: CFLOOP

    Your right, I don't think I needed th efirst query as I just used joins to
    accomplish the same thing. And what I actually need to be able to do is somehow
    display teh first location we hold races and then show the dates grouped by
    months after the location (as shown below). This is what I do have currently:

    Race Location Here

    date of race here
    date of race here

    ================================
    This is what I need thought:
    Race Location Here

    September Races
    ===============
    date here
    date here

    October Races
    ===============
    date here
    date here

    Second Race Location Here

    September Races
    ===============
    date here
    date here

    October Races
    ===============
    date here
    date here

    How could I now also group the output by months. So any date of race in
    september at location 2 would display under location 2, september ...

    Thanks for the help,


    cfuser7 Guest

  7. #7

    Default Re: CFLOOP

    Check out the doentation for the <cfquery ...> tag and its group
    argument.

    Basically you create a query that orders your results by location, then
    by month. Use a query group="locationColumn". Then inside that have a
    <cfquery group="monthColumn" then inside that have a <cfquery> no group
    argument for the race details.
    Ian Guest

  8. #8

    Default Re: CFLOOP

    I don't think you can have 2 <cfoutput query="something" group="something"> nested together. I have tried and get an error.


    cfuser7 Guest

  9. #9

    Default Re: CFLOOP

    I don't think you can have 2 <cfoutput query="something"
    group="something"> nested together. I have tried and get an error.

    Yes you can - note the correct cfoutput syntax. If you where to read
    the doentation for cfoutput and how ColdFusion handles it you would
    see how it is done, there's even cut and paste examples.

    <cfoutput query="theQuery" group="aColumn">
    Do stuff every time the value for aColumn changes.
    <cfoutput group="bColumn">
    Do Stuff every time the value for bColumn changes.
    <cfoutput>
    Do stuff for every record in theQuery.
    </cfoutput>
    Do Stuff every time the value for bColumn changes.
    </cfoutput>
    Do Stuff every time the value for aColumn Changes.
    </cfoutput>
    Ian Guest

  10. #10

    Default Re: CFLOOP

    Your the man! Thanks for the help. Worked great.
    cfuser7 Guest

Similar Threads

  1. Question Need help with MOD and cfloop
    By TheBorg in forum ColdFusion
    Replies: 0
    Last Post: May 30th, 07:18 AM
  2. cfloop
    By drmaves in forum Coldfusion - Getting Started
    Replies: 10
    Last Post: September 13th, 04:36 PM
  3. cfloop trouble
    By Vampyr_Bytes in forum Coldfusion - Getting Started
    Replies: 3
    Last Post: August 26th, 08:22 AM
  4. Cfloop..
    By Seth Buntin in forum Coldfusion - Advanced Techniques
    Replies: 4
    Last Post: June 29th, 05:17 PM
  5. to cfloop or not to cfloop?
    By chriskeeler2 in forum Macromedia ColdFusion
    Replies: 3
    Last Post: June 20th, 07:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139