Solved

creating a custom table for Displaying the Data

Posted on 2013-06-18
4
254 Views
Last Modified: 2013-06-21
Hi, I have the following string and i want to split that string to display data in table format but the way i want to display is not working, Here is the data and here is how it should look like

vendorname- #name#: city-#city#: state-#state#:zip-#zip#:in network-#innetwork#

Open in new window


i want to create the above as the following table:

<table>
<tr>
     <td>vendorname</td><td>#vendorname#</td>
     <td>city</td><td>#city#</td>
     <td>state</td><td>#state#</td>
</tr>
<tr><td>zip</td><td>#zip#</td>
<td>&nbsp;</td><td>&nbsp;</td>
<td>&nbsp;</td><td>&nbsp;</td>
</tr>
</table>

trying to create 6 columns in one TR

Here is try so far

<table align="center" width="100%" border="0" cellpadding="4" cellspacing="6" bordercolor="#CCCCCC;">
  <tr>
    <cfloop index="aPair" list="#Demo_Details#" delimiters=":">
    <cfset Key= listFirst(aPair,"-")>
    <cfif listLen(apair,"-") gt 1>
      <cfset value= listLast(aPair,"-")>
      <cfelse>
      <cfset value = "">
    </cfif>
    <cfoutput>
    <td><strong>#key#</strong></td>
    <td>#value#</td>
    </cfoutput>
    </cfloop>
  </tr>
</table>
0
Comment
  • 2
4 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 250 total points
ID: 39256749
You left out "network", but if this must be dynamic ...

Create a counter variable to track the # of columns displayed. Increment it each time you loop. When it reaches 6, start a new row and reset it.

<table ...>
<tr>
<cfset columns = 0>
<cfloop index="aPair" list="#Demo_Details#" delimiters=":">

    ..  your existing code ....


     <cfset columns = columns + 2>
     <!--- start new row and reset --->
     <cfif columns gte 6>
          </tr></tr>
          <cfset columns = 0>
     </cfif>
</cfloop>
</tr>
</table>
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 39257048
so it will be like this

<table ...>
<tr>
<cfset columns = 0>
<cfloop index="aPair" list="#Demo_Details#" delimiters=":">
    <cfset Key= listFirst(aPair,"-")>
    <cfif listLen(apair,"-") gt 1>
      <cfset value= listLast(aPair,"-")>
      <cfelse>
      <cfset value = "">
    </cfif>
    <cfoutput>
    <td><strong>#key#</strong></td>
    <td>#value#</td>
    </cfoutput>
     <cfset columns = columns + 2>
     <!--- start new row and reset --->
     <cfif columns gte 6>
          </tr></tr>
          <cfset columns = 0>
     </cfif>
</cfloop>
</tr>
</table>

i am ooo now, so will try in morning

Thanks
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39257060
Yeah, that looks right. I'll check back tomorrow.
0
 
LVL 28

Assisted Solution

by:Pravin Asar
Pravin Asar earned 250 total points
ID: 39257705
Here is good example code for you.

<cfset str=ArrayNew(1)/>
<cfset str[1]="vendorname- valuename1: city-valuecity1: state-valuestate1:zip-valuezip1:in network-valueinnetwork1"/>
<cfset str[2]="vendorname- valuename2: city-valuecity2: state-valuestate2:zip-valuezip2:in network-valueinnetwork2"/>
<cfset str[3]="vendorname- valuename3: city-valuecity3: state-valuestate3:zip-valuezip3:in network-valueinnetwork3"/>
<table>
<cfloop index="lx" from="1" to="#arraylen(str)#" >

<cfset strArray=ListToArray(str[lx],":",1)/>
<!--- Create Header Row --->
<cfif lx eq 1>
<tr>
<cfloop index="idx" from="1" to="#arraylen(strArray)#">
<cfoutput><th>#ListGetAt(strArray[idx],1,"-")#</th></cfoutput>
</cfloop>
</tr>
</cfif>
<!--- Create Data Rows --->
<tr>
<cfloop index="idx" from="1" to="#arraylen(strArray)#">
<cfoutput><td>#ListGetAt(strArray[idx],2,"-")#</td></cfoutput>
</cfloop>
</tr>
</cfloop>
</table>
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question