SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry 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

  2. #2
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    Code:
    <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>

  3. #3
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Aberdeen, Scotland
    Posts
    379
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice bit of coding there Phil ;-)

  4. #4
    SitePoint Evangelist
    Join Date
    Mar 2007
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <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>
    Good job figuring things out. One small suggestion. Move the link inside the CFIF so you don't generate an empty link.

    Code:
    <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>

  5. #5
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Aberdeen, Scotland
    Posts
    379
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <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

    http://www.cfdeveloper.co.uk/forum/f...696&PN=0&TPN=1

  6. #6
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LOL

    Its good to share... hehehe

  7. #7
    SitePoint Evangelist
    Join Date
    Mar 2007
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oooh.. now I understand Clarkee21's wink ;-)

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

  8. #8
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Aberdeen, Scotland
    Posts
    379
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  9. #9
    SitePoint Evangelist
    Join Date
    Mar 2007
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

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

  10. #10
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Aberdeen, Scotland
    Posts
    379
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    He had some issues with Distinct as well ;-)

  11. #11
    SitePoint Evangelist
    Join Date
    Mar 2007
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you say so All I saw was only extracting one field. Yet not being able to use a SQL distinct for some reason .. ? I dunno

  12. #12
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Aberdeen, Scotland
    Posts
    379
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am in no position to prove OR disprove that statement at this given time.

  13. #13
    SitePoint Evangelist
    Join Date
    Mar 2007
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess PhilJ2008 has no comment too


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •