Solved

creating a custom table for Displaying the Data

Posted on 2013-06-18
4
252 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
Question by:myselfrandhawa
  • 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 15

Author Comment

by:myselfrandhawa
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Upgrading Internet Information Server 12 93
Build PDF in coldfusion 2 55
cfpdfform and populate 14 58
Align a <div> to a table row 3 38
Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now