Array output question

Hi all

I have an array and need to output the data in it into a table.

Each row will have five columns and then create a new row if necessary to continue outputting the contents of the array. The layout will look something like this:

Sports Mens Womens Kids Toys
Health Beauty Phones Gaming…

I have no idea how to get this to work. Any suggestions would be great.

Thanks

Phil

I guess PhilJ2008 has no comment too :wink:

I am in no position to prove OR disprove that statement at this given time. :lol:

If you say so :wink: All I saw was only extracting one field. Yet not being able to use a SQL distinct for some reason … ? I dunno :slight_smile:

I didn’t have time to read the whole thing in detail. It sounded like he just needed distinct names, which a QoQ could do easily. But I may have missed something :wink:

But right now duty beckons. So I’ll have to review it later.

He had some issues with Distinct as well :wink:

<cfset name = " " />
<cfif recNum lte arrayLen(cleanArray)>
<cfset name = cleanArray[recNum] />
</cfif>
<td class=“catList”><a href=“categories3.cfm?table=#URL.table#&searchItem=#name#”>#name#</a></td>

Well ok that bit isn’t my code :lol:

http://www.cfdeveloper.co.uk/forum/forum_posts.asp?TID=696&PN=0&TPN=1

Have a look at that cfdeveloper.co.uk link on my last point… we went through those options, apart from the QoQ.

Phil mentioned that he’d converted to an array just before this code to remove some duplicates so that’s the reason behind this approach.

Nice bit of coding there Phil :wink:

Hi All

Worked out the issue and here is the code for what I did, in case someone else needs it at a later stage.

<cfset noPerRow = 3 />
<cfset start = 1 />
<cfset finish = noPerRow />
<cfoutput>
     <table>
              <cfloop condition="start lte arrayLen(cleanArray)">
                   <tr>
                        <cfloop from="#start#" to="#finish#" index="recNum">
                                    <cfset name = " " />
                                     <cfif recNum lte arrayLen(cleanArray)>
                                       <cfset name = cleanArray[recNum] />
                                     </cfif>
                                     <td class="catList"><a href="categories3.cfm?table=#URL.table#&searchItem=#name#">#name#</a></td>
                           </cfloop>
                        <cfset start = finish+1 />
                        <cfset finish += noPerRow />
                   </tr>
              </cfloop>
     </table>
</cfoutput>
        &lt;cfset name = " " /&gt;
                                 &lt;cfif recNum lte arrayLen(cleanArray)&gt;
                                   &lt;cfset name = cleanArray[recNum] /&gt;
                                 &lt;/cfif&gt;
                                 &lt;td class="catList"&gt;&lt;a href="categories3.cfm?table=#URL.table#&searchItem=#name#"&gt;#name#&lt;/a&gt;&lt;/td&gt;

Good job figuring things out. One small suggestion. Move the link inside the CFIF so you don’t generate an empty link.


<cfif recNum lte arrayLen(cleanArray)>
   <cfset name = cleanArray[recNum] />
   <td class="catList"><a href="categories3.cfm?table=#URL.table#&searchItem=#name#">#name#</a></td>
</cfif>

Oooh… now I understand Clarkee21’s wink :wink:

BTW: Do you really need arrays for this? Can’t you just do a QoQ or maybe cfoutput’s group attribute …?

LOL

Its good to share… hehehe