Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Using cfloop to ignore repeated values - help

Explorer ,
Oct 18, 2006 Oct 18, 2006
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
713
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 18, 2006 Oct 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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Oct 18, 2006 Oct 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 30, 2006 Oct 30, 2006
LATEST
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>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources