repeating records when using cfoutput

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default repeating records when using cfoutput

    For some reason this code being looped through and outputting 4 records then 3
    records then 2 records then 1 record. any ideas why? and how to fix it?

    <cfoutput query="Recordset1">
    <table cellpadding="2" cellspacing="0" border="0">
    <cfset col = 1><tr>
    <cfoutput>
    <td><img src="#Recordset1.PictureURL#" alt="#Recordset1.PictureURL#"
    width="#Recordset1.width#"
    height="#Recordset1.height#"><br>#Recordset1.capti on#</td>
    <cfif col IS 2></tr><cfset col = 1><cfelse><cfset col = 2></cfif>
    </cfoutput>
    <cfif col IS 2><td>&nbsp;</td></tr></cfif>
    </table>
    </cfoutput>

    brokerandy25 Guest

  2. Similar Questions and Discussions

    1. Cfoutput help!!!
      I am trying to figure out how to output records from a query that is returing 2 distinct table rows from each query. THe out put needs to look like...
    2. cfoutput and css
      I declare an entire document within a <cfoutput> </cfoutput> section. I am trying to insert the following css style descriptor into the code: ...
    3. cfoutput prblem
      Hi: I made a registration page with coldfusion, then I want the user to edit it's info. So I started the page with a cfquesry and then a cfoutput ...
    4. Organizing CFoutput?
      I am working with a MySQL database that I am pulling information about shops from all over the world and country. I am pulling the information...
    5. <cfoutput>
      Hi. I'm trying to rename a file but I get an error message. My code looks someting like this: <cfset source='C:\MyDocs\old.doc'> <cfset...
  3. #2

    Default Re: repeating records when using cfoutput

    What do you mean by "Fix it"? What do you want it to do? Also, you have a cfoutput nested within your cfoutput "query". It doesn't look like it is necessary for the code you have posted.
    mxstu Guest

  4. #3

    Default Re: repeating records when using cfoutput

    sorry little vague, I am well aware of the nesting of the output tags. I am
    trying to query a data base and pull out all relevant picture <img src>'s and
    captions and output like this
    1 2
    1.c 2.c
    3 4
    3.c 4.c

    I am having the hardest time with this.

    And I do appreciate the help

    andy

    brokerandy25 Guest

  5. #4

    Default Re: repeating records when using cfoutput

    Try

    SELECT DISTINCT

    in your query


    --
    Bill

    Marketweaver Module For Cartweaver
    [url]http://www.datapacks.com[/url]
    New Support Newsgroup: [url]http://www.datapacks.com/home.cfm?ThisPage=support[/url]
    Blog: [url]http://www.datapacks.com/Blog/[/url]
    Cartweaver Add-ons & Custom Cartweaver Modifications


    Skype Username: DataPacks.com

    "brokerandy25" <webforumsuser@macromedia.com> wrote in message
    news:darron$7je$1@forums.macromedia.com...
    > sorry little vague, I am well aware of the nesting of the output tags. I
    > am
    > trying to query a data base and pull out all relevant picture <img src>'s
    > and
    > captions and output like this
    > 1 2
    > 1.c 2.c
    > 3 4
    > 3.c 4.c
    >
    > I am having the hardest time with this.
    >
    > And I do appreciate the help
    >
    > andy
    >

    Bill Guest

  6. #5

    Default Re: repeating records when using cfoutput

    Bill I appreciate the effort, but unfortunately that did not help, could it be
    that this is an Access DB that is causing problems, or do you have some code
    that would work better for what I am trying to do?



    brokerandy25 Guest

  7. #6

    Default Re: repeating records when using cfoutput

    The posted code, while not optimal, is not the source of the stated problem.

    The problem must be in the query or some other section of code.

    Also when posting code, please use the "Attach Code" button.

    Thanks,
    -- MikeR

    MikerRoo Guest

  8. #7

    Default Re: repeating records when using cfoutput

    I think the problem is in your code. You are using one CFOUTPUT nested inside
    another. Normally this is done when you group on one of the fields -- the
    second CFOUTPUT will display all individual records that are part of the group.

    Your code looks like the the first (or outer) CFOUTPUT will loop through each
    of the four records returned by your query. The second or inner CFOUTPUT would
    then loop through all remaining records and display them. That is why you get
    first 4 records, then 3, etc.

    What exactly are you trying to accomplish? I thought you posted this problem
    earlier with some different code.

    -Paul


    dempster Guest

  9. #8

    Default Re: repeating records when using cfoutput

    I stand corrected. It IS the inner <cfoutput>.
    You've set up an accidental query grouping. (And Macromedia considers this a "feature"!)
    MikerRoo Guest

  10. #9

    Default Re: repeating records when using cfoutput

    Al right so How do I rectifiy this grouping problem? I wiped out all html (non
    Relevant code) so this is it for the page. I really do appreciate everyone
    taking the time to look at this.

    Paul I did post this question earlier, with different code, and I was not able
    to find a slution with that code, so I started again.

    As for what I am trying to do, I will try to reexplain. Though I will take
    the long route. My client wants to be able to up load photos to their web site
    and have them automatically appear on the appropriate pages. So using cffile
    we upload the file to the server, append the reletave path to the name of the
    file and and input all relevant info into DB ( caption, page number for picture
    to apper on, and img src '[EX: ../../Images/uploadedpictures/ ] ) Then we
    query DB to pull all pictures based upon page number, (Here is where the
    problem comes in) I want to pull all info from DB and out put it into a table,
    2 pictures per row, with captions. Now the code I am currently using displays
    records 1,2,3,4, then it repeats and displays records 3,2,1, then it repeats
    and displays records 2,1 then just record 1. I have had this problem before
    and it has been tied to cfoutput when outputting query results, I don't know
    how I have managed to fix the problem before, I have always just deleted and
    redone it.




    Andy

    <cfquery name="Recordset1" datasource="KidneyIndiana">
    SELECT Distinct * FROM PictureTable WHERE PageToAppearON =
    '#URL.PageToAppearON#'
    ORDER BY AutoNumber DESC
    </cfquery>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>NKF - Summer Camp</title>
    brokerandy25 Guest

  11. #10

    Default Re: repeating records when using cfoutput

    Okay, Replace the output section with the attached.

    It will display two pictures per row.

    -- MikeR


    <div id="Layer2" style="position:absolute; left:21px; top:168px; width:768px;
    height:94px; z-index:1; visibility: visible;"
    onMouseOver="MM_showHideLayers('sub5','','hide','s ub4','','hide','sub3','','hide
    ','sub2','','hide','menu1','','hide')">
    <!--- **** This font tag is not always closed. **** ---><font
    color="#993399" size="+2" face="Arial, Helvetica, sans-serif">
    <CFIF recordset1.recordcount EQ 0>
    </font>
    <div align="center"><font color="#993399" size="+2" face="Arial,
    Helvetica, sans-serif">We
    are sorry, but we have not uploaded any pictures for this event.<br>
    Please check back often.</font> </div>
    <CFELSE>
    <CFSET iPicsPerRow = 2>

    <table cellpadding="2" cellspacing="0" border="0">
    <tr>
    <CFOUTPUT query="Recordset1">
    <td>
    <img src="#Recordset1.PictureURL#" alt="#Recordset1.PictureURL#"
    width="#Recordset1.width#" height="#Recordset1.height#">
    <br>#Recordset1.caption#
    </td>
    <CFIF 0 EQ (CurrentRow MOD iPicsPerRow)> </tr><tr> </CFIF>
    </CFOUTPUT>
    </tr>
    </table>
    </CFIF>
    </div>

    </body>
    </html>

    MikerRoo Guest

  12. #11

    Default Re: repeating records when using cfoutput

    MikeRoo - thank you very much. I really appreciate the time, and if you would
    like to take the time, could you explain the code. I know that sounds stupid,
    but I cann't find any documentaion on the MOD.

    Thank you,

    Andy

    brokerandy25 Guest

  13. #12

    Default Re: repeating records when using cfoutput

    Mod is a fairly common operator in many programming languages.
    The CF version is documented
    [url]http://livedocs.macromedia.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/[/url]
    wwhelp.htm?context=ColdFusion_Documentation&file=0 0000926.htm.

    CurrentRow MOD XXX will only be zero on every XXX'th row in the recordset.
    In this case, that is when we want to start a new table row.

    MikerRoo Guest

  14. #13

    Default Re: repeating records when using cfoutput

    Also, I should have used "Recordset1.CurrentRow" in the code to be a little clearer and to make the code more robust.

    MikerRoo Guest

  15. #14

    Default Re: repeating records when using cfoutput

    Awesome, thanks dude.

    brokerandy25 Guest

Posting Permissions

  • You may not post new threads
  • You may 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