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#
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> </td><td> </td>
<td> </td><td> </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>
It is not generating the columns as expected, it is showing everything in single line
How about something like this
<cfset Vendor = "">
<cfset City = "">
<cfset State = "">
<cfset ZIP = "">
<cfloop index="aPair" list="#Demo_Details#" delimiters=":">
<cfset Key= listFirst(aPair,"-")>
<cfif listLen(apair,"-") gt 1>
<cfset SetVariable(key, listLast(aPair,"-")>
</cfif>
</cfloop>
<cfoutput>
<table align="center" width="100%" border="0" cellpadding="4" cellspacing="6" bordercolor="#CCCCCC;">
<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> </td><td> </td>
<td> </td><td> </td>
</tr>
</table>
</cfoutput>
Related
I have a query written in a stored procedure and the data is dumping just fine. Some of the results return [empty string] and in those cases, I'm trying to output a different message. Here's what I have thus far:
Looping through the query:
<cfloop query="#inactiveAdmins#">
<tr>
<td class="text-left">#Admin_Name#</td>
<td class="text-left">#Dept_Name#</td>
<td class="text-left">#Acad_Lead#</td>
<td class="text-left">#Acad_Lead_Email#</td>
<td class="text-right">#dateFormat(Last_Logon, 'mmm dd, yyyy')#</td>
</tr>
</cfloop>
At the top of the page, I'm running this cfif statement.
<cfif #inactiveAdmins.Last_Logon# eq "">
Never Logged On
<cfelse>
#inactiveAdmins.Last_Logon#
</cfif>
But, in my output, I'm still getting a display with no message.
When I try to run the condition inside the loop, I get the following:
Is this supposed to be inside your table? Make sure you wrap it inside a tr and td.
<cfloop query="#inactiveAdmins#">
<tr>
<td class="text-left">#Admin_Name#</td>
<td class="text-left">#Dept_Name#</td>
<td class="text-left">#Acad_Lead#</td>
<td class="text-left">#Acad_Lead_Email#</td>
<td class="text-right">#(Len(Last_Logon) ? dateFormat(Last_Logon, 'mmm dd, yyyy') : 'Never Logged On')#</td>
</tr>
</cfloop>
Or the long form:
<cfloop query="#inactiveAdmins#">
<tr>
<td class="text-left">#Admin_Name#</td>
<td class="text-left">#Dept_Name#</td>
<td class="text-left">#Acad_Lead#</td>
<td class="text-left">#Acad_Lead_Email#</td>
<td class="text-right">
<cfif Len(Last_Logon)>
#dateFormat(Last_Logon, 'mmm dd, yyyy')#
<cfelse>
Never Logged On
</cfif>
</td>
</tr>
</cfloop>
I have the following cfdocument code:
<cfdocument format="pdf" orientation = "landscape" bookmark="Yes" marginleft=".25" marginright=".25" marginTop = ".75" marginbottom=".75" scale="90" localUrl="yes">
<cfoutput>
<cfdocumentsection name="Summary Page" marginleft=".25" marginright=".25" marginTop = "1.65" marginbottom="1" >
<cfdocumentitem type="header">
<center>
<table width="1000" height="200" cellpadding="3" cellspacing="0">
<tr><td>Header Page</td></tr>
</table>
</center>
</cfdocumentitem>
<cfloop query="first_query">
<cfquery name="getDetails" dbtype="query">
select * from first_query
where type= <cfqueryparam cfsqltype="cf_sql_varchar" value="#Type#">
</cfquery>
<cfsavecontent variable="trhead">
<tr class="bigbluecolor" style="text-align:center;">
<td width="6%">Term</td<
</tr>
</cfsavecontent>
#trhead#
<cfloop query="getDetails">
<tr align="center">
<td width="6%">#Listfirst(TermYears,'.')# Years</td>
</tr>
<cfif getDetails.recordcount GT 6 AND getDetails.currentRow EQ 6>
<cfdocumentitem type="pagebreak"/>
#trhead#
</cfif>
</cfloop>
</table>
</td></tr></table>
</cfloop>
</cfoutput>
</cfdocumentsection>
</cfdocument>
However, it does not do the page break. It shows empty pages at the top and then it starts breaking anywhere it wants. I want my inner loop to break after 4 records and the <TH> header to repeat itself again on the start of the second page.
The trhead variable contains the code which I have wrapped with the savecontent to show it.
Can anyone explain what I am missing?
The unpredictability of the page breaks is because of this:
<cfif getDetails.recordcount GT 6 AND getDetails.currentRow EQ 6>
If getDetails has less than 6 records, that condition will never return true. Plus, if you have 12 or more records, it won't return true. I suggest this approach. First, add this to first_query:
order by type
Then build your content like this:
<cfsavecontent variable="trhead">
<tr class="bigbluecolor" style="text-align:center;">
<td width="6%">Term</td>
</tr>
</cfsavecontent>
<cfoutput query="first_query">
other content goes here
<cfif currentRow mod 6 is 0>
<cfdocumentitem type="pagebreak"/>
#trhead#
</cfif>
</cfoutput>
I am trying to figure out how to run queries through a MS sql database using ColdFusion in order to make a table that keeps track of Location, Percent of Total Checklists, and Location Total.
I am having trouble looping to show my locations only once and to run the totals for each location. I am not sure why my table is adding all of these lines like the picture below, any help with this would be greatly appreciated!
<cfset result = {} />
<cftry>
<cfquery datasource="#application.dsn#" name="GetLocationInfo">
SELECT *
FROM cl_checklists
</cfquery>
<cfcatch type="any">
<cfset result.error = CFCATCH.message >
<cfset result.detail = CFCATCH.detail >
</cfcatch>
</cftry>
<table border="1" id="Checklist_Stats">
<thead>
<th><strong>Location</strong></th>
<th><strong>Percent of Total Checklists</strong></th>
<th><strong>Location Total</strong></th>
</thead>
<tbody>
<cfquery name="allLocCode" dbtype="query">
SELECT DISTINCT trans_location, COUNT(*) AS locCntr FROM GetLocationInfo GROUP BY trans_location ORDER BY trans_location
</cfquery>
<cfloop query="allLocCode">
<cfset thisLocationName = trim(allLocCode.trans_location) />
<cfoutput query="allLocCode">
<tr>
<td><strong>#thisLocationName#</strong></td>
<td></td>
<td></td>
</tr>
<cfset thisLocationName = "" />
</cfoutput>
</cfloop>
</tbody>
<!--- Total of All Sum of each column --->
<tr>
<td><strong>Total</strong></td>
<td></td>
<td></td>
</tr>
</table>
You only need to loop through the query once. Remove the additional cfoutput
<cfoutput query="allLocCode">
<cfset thisLocationName = trim(allLocCode.trans_location) />
<tr>
<td><strong>#thisLocationName#</strong></td>
<td></td>
<td></td>
</tr>
</cfoutput>
Your code creates a nested loop.
<cfloop query="allLocCode"> // loop over all items in the query
<cfset thisLocationName = trim(allLocCode.trans_location) />
<cfoutput query="allLocCode"> // loop again over all items in the query
<tr>
<td><strong>#thisLocationName#</strong></td> // print the string
<td></td>
<td></td>
</tr>
<cfset thisLocationName = "" /> // empties the string, hence next rows will be empty
</cfoutput>
</cfloop>
Change the line <cfoutput query="allLocCode"> to <cfoutput>.
I have a report which is doing a page-break on a tfoot tag.
<style type="text/css">
#media print
{
tfoot{page-break-after:always}
}
</style>
The output comes from a query (here called "test"), ordered by state. The report is in a table and I want to break after each state. It's PAGING correctly. But the problem is that the first header (for the first state) precedes and the first footer (for the first state) follows each subsequent header and footer. In my test program I worked around it by inventing a blank state and setting its header and footer to blank. However, in my real program things are too complicated to do that; and I don't like kluges anyway. Can anyone tell me how to get that first header and footer to appear just once where they are supposed to be? Here is the test program:
<cfset statels = (" ,DE,NC,MD")> <!--- the blank state is the kluge --->
<cfset i = 0>
<table style = "margin-left: 50px">
<cfloop list = #statels# index = "state">
<cfset i = i + 1>
<cfoutput>
<thead>
<cfif i EQ 1>
<tr><td>  </td></tr>
<cfelse>
<tr>
<td style = "border:1px solid green">This is a Header #state#</td>
<td> <img src="http://localhost/reports/XYZinc.jpg" alt="picture"> </td>
</tr>
<!--- column headings to be on each page --->
<tr>
<cfloop array = #test.GetColumnList()# index = "col">
<td class = "repsort">#col# </td>
</cfloop>
</tr>
</cfif>
</thead>
</cfoutput>
<cfoutput query = "test">
<cfif test["PersonState"][currentrow] EQ state>
<tr>
<cfloop array = #test.GetColumnList()# index = "col">
<td>#test[col]currentrow]# </td>
</cfloop>
</tr>
</cfif><!--- personstate is state --->
</cfoutput>
<cfoutput>
<tfoot>
<cfif i EQ 1>
<tr><td>  </td></tr>
<cfelse>
<tr>
<td>This is a footer<br> i is #i# state is #state#
</td>
</tr>
</cfif>
</tfoot>
</cfoutput> <!---query = test --->
</cfloop> <!--- i loop --->
</table>
I have the following ColdFusion code that is getting information from a database and displaying the results on the homepage. Here's the cfquery code:
<cfquery name="getSchedule" datasource="#APPLICATION.datasource#" dbtype="odbc">
SELECT * FROM SCHEDULE_Days SD
LEFT JOIN SCHEDULE_ScheduledClasses SSC ON SD.day_id = SSC.day_id
LEFT JOIN SCHEDULE_Classes SC ON SSC.class_id = SC.class_id
WHERE SD.day_date = #createODBCDate(now())# AND SSC.schedule_cancelled = 0
ORDER BY SSC.start_time
</cfquery>
and the output code:
<cfoutput>
<cfloop query="getSchedule">
<tr>
<td width="40"> </td>
<td width="74">#lcase(timeFormat(start_time,"h:mm tt"))#</td>
<td width="158">#class_name#</td>
</tr>
</cfloop>
</cfoutput>
The issue is, if there is no data contained within getSchedule (i.e., there are no ScheduledClasses), it displays nothing.
I'm looking for a way to change this so that, in the event that there is no data to display, I can specify a message and code to be shown in its absence.
First just a quick CF tip you can make you code better by doing it this way:
<cfif getSchedule.recordcount GT 0>
<cfoutput query="getSchedule">
<tr>
<td width="40"> </td>
<td width="74">#lcase(timeFormat(getSchedule.start_time,"h:mm tt"))#</td>
<td width="158">#getSchedule.class_name#</td>
</tr>
</cfoutput>
<cfelse>
<p>Empty record message here</p>
</cfif>
The reason I put the query output first is most likely this will happen more than with your empty set message.
<cfif getSchedule.recordcount>
.... do something
</cfif>
Will work just aswell there is no need for gt 0
Use the recordCount to detect whether the query has any record
<cfif getSchedule.recordcount gt 0>
.... do something
</cfif>
<cfif getSchedule.RecordCount>
<table>
<cfoutput query="getSchedule">
<tr>
<td width="40"> </td>
<td width="74">#lcase(timeFormat(start_time,"h:mm tt"))#</td>
<td width="158">#class_name#</td>
</tr>
</cfoutput>
</table>
<cfelse>
<p>There are currently no records</p>
</cfif>