Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

creating a custom table for Displaying the Data

Posted on 2013-06-18
4
Medium Priority
?
265 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 1000 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 29

Assisted Solution

by:Pravin Asar
Pravin Asar earned 1000 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

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

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

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 …
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

705 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