1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Looping or SQL problem

Discussion in 'Programming' started by devmonk, Oct 4, 2006.

  1. #1
    I have a template the creates an xml file from a series of DB queries. Everything is working fine but it is repeating the list of products once for each item in the list. For example instead of getting:

    <Designer>
    <Title>David Yerman</Title>
    <Products>
    <Product>
    <LargeView>yurman/l/img1.jpg</LargeView>
    <SmallView>yurman/s/img1.jpg</SmallView>
    </Product>
    <Product>
    <LargeView>yurman/l/img2.jpg</LargeView>
    <SmallView>yurman/s/img2.jpg</SmallView>
    </Product>
    </Products>
    <Designer>

    I get the following:

    <Designer>
    <Title>David Yurman</Title>
    <Products>
    <Product>
    <LargeView>yurman/l/img1.jpg</LargeView>
    <SmallView>yurman/s/img1.jpg</SmallView>
    </Product>
    <Product>
    <LargeView>yurman/l/img2.jpg</LargeView>
    <SmallView>yurman/s/img2.jpg</SmallView>
    </Product>
    <Product>
    <LargeView>yurman/l/img1.jpg</LargeView>
    <SmallView>yurman/s/img1.jpg</SmallView>
    </Product>
    <Product>
    <LargeView>yurman/l/img2.jpg</LargeView>
    <SmallView>yurman/s/img2.jpg</SmallView>
    </Product>
    <Product>
    <LargeView>danielk/l/img1.jpg</LargeView>
    <SmallView>danielk/s/img1.jpg</SmallView>
    </Product>
    <Product>
    <LargeView>danielk/l/img2.jpg</LargeView>
    <SmallView>danielk/s/img2.jpg</SmallView>
    </Product>
    <Product>
    <LargeView>danielk/l/img1.jpg</LargeView>
    <SmallView>danielk/s/img1.jpg</SmallView>
    </Product>
    <Product>
    <LargeView>danielk/l/img2.jpg</LargeView>
    <SmallView>danielk/s/img2.jpg</SmallView>
    </Product>
    </Products>
    </Designer>

    It is listing all products under each designer and reqeating the group of products once for each product that is in the list. The structure is correct and all else is working I just can't figure out how to change my looping structure or my query to get it to display correctly. My code is as follows:

    <cfxml variable="myDoc">
    <Products>
    <cfloop query="getCategories">
    <Category title="<cfoutput>#getCategories.txtTitle#</cfoutput>" label="<cfoutput>#getCategories.txtLabel#</cfoutput>">
    <cfquery name="getDesigners" datasource="octannerXML">
    SELECT txtTitle, txtWebsite, pk_designerID
    FROM tblDesigners
    INNER JOIN tblProducts
    ON tblDesigners.pk_designerID = tblProducts.numDesignerID
    WHERE tblProducts.numCatID = #getCategories.pk_catID# </cfquery>
    <Designer>
    <Title><cfoutput>#getDesigners.txtTitle#</cfoutput></Title>
    <Products>
    <cfloop query="getDesigners">
    <cfquery name="getProducts" datasource="octannerXML">
    SELECT *
    FROM tblProducts
    WHERE tblProducts.numCatID = #getCategories.pk_catID#
    AND tblProducts.numDesignerID = #getDesigners.pk_designerID#
    </cfquery>
    <cfoutput query="getProducts">
    <Product>
    <LargeView>#getProducts.txtLargeView#</LargeView>
    <SmallView>#getProducts.txtSmallView#</SmallView>
    </Product>
    </cfoutput>
    </cfloop>
    </Products>
    <Website target="_blank">
    <cfoutput>#getDesigners.txtWebsite#</cfoutput>
    </Website>
    </Designer>
    </Category>
    </cfloop>
    </Products>
    </cfxml>

    Any Help is appriciated!

    Thanks

    Jason
     
    devmonk, Oct 4, 2006 IP
  2. harsh789

    harsh789 Member

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #2
    Try using distinctrows in following query.

    SELECT DISTINCTROWS txtTitle, txtWebsite, pk_designerID
    FROM tblDesigners
    INNER JOIN tblProducts
    ON tblDesigners.pk_designerID = tblProducts.numDesignerID
    WHERE tblProducts.numCatID = #getCategories.pk_catID#
    Code (markup):
     
    harsh789, Oct 6, 2006 IP