Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6680343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:27:51+00:00 2026-05-26T04:27:51+00:00

I asked a question here yesterday ( cfquery grouping, counts & maxrows ) to

  • 0

I asked a question here yesterday (cfquery grouping, counts & maxrows) to which this is related. That question would successfully answered in as much as the count aspect is working successfully. However, I’m getting strange results with another aspect that I can quite figure out.

The scenario is this – I’m returning top-level categories and subcategories in a single query, the subcategories being returned by nesting cfoutput. The result works, with one exception – the subcategories are always returning the full list – i.e if I limit the initial output to return only 2 rows on screen, I’m always getting the first 2 rows from the first top-level category – now the first 2 rows from the ‘current’ top level category.

I’ve tried clearing the array within the cfoutput query, within the cfloop etc – all without success.

I’ve pasted my code below, and attached a screenshot of the current out it generates. Any pointers on this before I lose all my hair would be gratefully accepted!

<cfquery name="getcategories">
SELECT p.ID AS CategoryID, p.Cat_Name as CategoryName, p.Cat_Shortname, c.ID AS SubCategoryID, c.Cat_Name as SubCategoryName, c.Cat_Shortname AS SubCatShortname
FROM    product_categories p LEFT JOIN product_categories c ON p.ID = c.SubcategoryOf
WHERE  p.SubcategoryOf = 0
</cfquery> 
<cfset subcategoryNames = ArrayNew(1)>
        <cfoutput query="getcategories" group="CategoryName">
        <li class="catli">CategoryName : #CategoryName#</li> 
        <cfoutput>

          <cfset arrayAppend(subcategoryNames, SubcategoryName)>
          <p>ArrayAppend : #SubcategoryName#<br /></p>
        </cfoutput>

        <cfloop from="1" to="2" index="i">
            <li class="subli">SubcategoryName : #SubcategoryName[i]#</li>
        </cfloop>

        <cfif arrayLen(subcategoryNames) GT 2>
        <p>ArrayLen is GT 2</p>
          <li class="subli moreli">
            + #arrayLen(subcategoryNames) - 2# More Subcategories
          </li>
            <!--- Extra Subcategories --->
            <p>Extra Subcategories</p>
                <cfloop from="3" to="#arrayLen(subcategoryNames)#" index="r">
                <li class="subli">SubcategoryName : #SubcategoryName[r]#</li>
                </cfloop>

            <!--- End Extra Subcategories --->

        </cfif>

        </cfoutput>

screenshot

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:27:52+00:00Added an answer on May 26, 2026 at 4:27 am

    You should just be able to switch these two lines:

    <cfset subcategoryNames = ArrayNew(1)>
    <cfoutput query="getcategories" group="CategoryName">
    

    To this:

    <cfoutput query="getcategories" group="CategoryName">
        <cfset subcategoryNames = ArrayNew(1)>
    

    That will reset your array at the beginning of each new top-level category.

    You could also leave them in their original order, and just do this:

    <cfset subcategoryNames = ArrayNew(1)>
    <cfoutput query="getcategories" group="CategoryName">
        <cfset ArrayClear(subcategoryNames) />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While looking at a micro-optimization question that I asked yesterday ( here ), I
Yesterday I asked this general question about decimals and their internal precisions. Here is
I asked the question here and now i would like to reverse this procedure
I asked a question just yesterday which caused this new issue. gdb within emacs
I have asked this question here about a Python command that fetches a URL
This one is similar to a question that I asked yesterday. However my concern
I re-asked this question here because the people at ServerFault deemed that this is
I asked a question yesterday about a little app that I would like to
Yesterday I asked a question here that got more momentum that what I thought
Its similar question that I asked yesterday here with a slight modification. Here are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.