Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

creating a custom table for Displaying the Data

Posted on 2013-06-18
4
Medium Priority
?
268 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 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

886 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