Skip to main content
Inspiring
October 18, 2006
Question

Using cfloop to ignore repeated values - help

  • October 18, 2006
  • 3 replies
  • 718 views
I have a query that joins two tables for a price comparison site. the first table holds information about a product. the second table holds store specific information about a product. so a product in the first table is unique. In the second table the product is repeated depending on how many stores stock the product.

When I go through CFoutput the product is being duplicated which I want for certain screens but not others. I need a cfloop that checks to see if a product title is repeated and if so, move to the next product. without duplicating the product in cfoutput

any ideas???

thanks
    This topic has been closed for replies.

    3 replies

    Inspiring
    October 30, 2006
    Something like this: -

    <cfset foundTitles="">
    <table>
    <cfloop query="myQuery">
    <cfif listfind(foundTitles,myQuery.title) eq 0>
    <tr><td>Output this item</td></tr>
    <cfset foundTitles=listAppend(foundTitles,myQuery.title)>
    <Cfelse>
    <!---suppress it--->
    </cfif>

    </cfloop>
    </table>
    Participating Frequently
    October 18, 2006
    Need more information, such as are you trying to display information in a table, or do you want to display the product once, then all of the stores that stock it, etc. This is usually accomplished by an ORDER BY product in your query, then using the group attribute in cfoutput where you would display the product in the bable, then using a separate cfoutput eithin the table for the details, etc.

    Phil
    Inspiring
    October 18, 2006
    Add ORDER BY product into your query then use the group attribute in cfoutput to only display the products and not the repeated details.

    <cfquery... >
    select ...
    from ...
    where...
    ORDER BY product, ...
    </cfquery>


    To show only the products

    <cfoutput group="product">
    ...
    </cfoutput>


    To show multiple records for each product

    <cfoutput query="..." group="product">
    ...
    <cfoutput>
    ...
    </cfoutput>
    </cfoutput>

    OR

    <cfoutput query="...">
    ...
    <cfoutput>