Library code snippets

Create a Percentage Table

This page gives another example of my ColdFusion programming for Gilway Lighting. The task at hand was to establish a chart that recorded the number of magazines checked off (such as EEM, Thomas), and then compute the percentages of the total every time the form is submitted. Of course, this is not the actual form, but Gilway encouraged me to put the testing form on the web, and allowed me to use one of their tables.

See for yourself how the forms and number of applicants are incremented, and how the percentages follow. Also, a counter for National and International Respondents in included, and an email is sent out to gilway with the results. The code that does most of the work is below, and is on the sub_gil2.cfm page.

Use the links that follow to access the sample form. The Code below, copy it into Notepad first, before treating as HTML.

Submission Form for Percentage Table for Gilway Lamps

<CFMAIL TO= "gilway@cheshiregroup.com"
CC= "juliag@shore.net"
FROM= "#EMAIL#"
SUBJECT= "Registration with Gilway Technical Lamp">

These are the results of a recent inquiry.

Engineering Form Catalog?: #IIf(isdefined("form.ENGFORM"), DE('Yes'), DE('No'))#
1999 Short Form Catalog?: #IIf(isdefined("form.SHORT"), DE('Yes'), DE('No'))#

How did you hear about Gilway Lamp:

EEM: #IIf(isdefined("form.EEM"), DE('Yes'), DE('No'))#
Thomas Register: #IIf(isdefined("form.THOMAS"), DE('Yes'), DE('No'))#
Magazine Advertisment: #IIf(isdefined("form.MAG"), DE('Yes'), DE('No'))#
Mailer: #IIf(isdefined("form.MAILER"), DE('Yes'), DE('No'))#
Search Engine: #IIf(isdefined("form.SEARCH"), DE('Yes'), DE('No'))#
Company Colleague: #IIf(isdefined("form.COMPANY"), DE('Yes'), DE('No'))#
Other: #IIf(isdefined("form.OTHER"), DE('Yes'), DE('No'))#


Full Name: #NAME#
Title: #TITLE#

Company or Organization: #CO#

Address:

#STREET#
#CITY# #STATE# #COUNTRY# #ZIP#

Business Phone: #PHONE#
Business Fax: #FAX#

Email: #EMAIL#

Comments:

#COMMENTS#
</CFMAIL>

</BODY>
</HTML>
<CFINSERT DATASOURCE="cgi2" TABLENAME="tblgil2">

<CFQUERY NAME="GetQuery" DATASOURCE="cgi2">
SELECT count(EEM) AS eem, count(ENGFORM) as eng, count(SHORT) as short, count(THOMAS) as thomas, count(MAG) as mag, count(MAILER) as mailer, count (SEARCH) as search, count (COMPANY) as company, count(OTHER) as other, count(NAME) as name, count(STATE) as state, count(COUNTRY) as country
FROM tblgil2
</cfquery>
<table border=1>
<CFSET TOTAL = (#GetQuery.eem#+#GetQuery.thomas#+#GetQuery.mag# + #GetQuery.mailer# + #GetQuery.search# + #GetQuery.company# + #GetQuery.other#)>
<CFSET ENG = (#GetQuery.eng#/#TOTAL#)*100>
<CFSET SHORT = (#GetQuery.short#/#TOTAL#)*100>
<CFSET EEM = (#GetQuery.eem#/#TOTAL#)*100>
<CFSET THOMAS = (#GetQuery.thomas#/#TOTAL#)*100>
<CFSET MAG = (#GetQuery.mag#/#TOTAL#)*100>
<CFSET MAILER = (#GetQuery.mailer#/#TOTAL#)*100>
<CFSET SEARCH = (#GetQuery.search#/#TOTAL#)*100>
<CFSET CO = (#GetQuery.company#/#TOTAL#)*100>
<CFSET OTHER = (#GetQuery.other#/#TOTAL#)*100>
<CFSET TOTCTRY = #GetQuery.country#>
<CFSET FOREIGN = #TOTCTRY#-#GetQuery.state#>
<CFSET FORPER = (#FOREIGN#/#TOTCTRY#)*100>
<CFSET USPER = (#GetQuery.state#/#TOTCTRY#)*100>

<cfoutput>
<tr><td>
TOTAL NUMBER OF RESPONDENTS:</td> <td> #GetQuery.name#</td></tr>
<tr><td>Total Engineering Form Catalog:</td><td> #GetQuery.eng# </td></tr>
<tr><td>Total Short Form Catalog:</td><td> #GetQuery.short#</td></tr>
<tr><td>Total EEM:</td><td> #GetQuery.eem#</td></tr>
<tr><td>Total Thomas Register:</td><td> #GetQuery.thomas#</td></tr>
<tr><td>Total Magazine Advertisement:</td><td> #GetQuery.mag#</td></tr>
<tr><td>Total Mailer:</td><td> #GetQuery.mailer#</td></tr>
<tr><td>Total Search Engine:</td><td> #GetQuery.search#</td></tr>
<tr><td>Total Company Colleague:</td><td> #GetQuery.company#</td></tr>
<tr><td>Total Other:</td><td> #GetQuery.other#</td></tr>
<tr><td>TOTAL FROM EEM TO OTHER:</td><td> #TOTAL#</TD></TR>
<tr><td>% of EEM: </td><td>#NumberFormat(EEM,"__.__")# %</td></tr>
<tr><td>% of Thomas Register: </td><td>#NumberFormat(THOMAS,"__.__")# %</td></tr>
<tr><td>% of Magazine Advertisement: </td><td>#NumberFormat(MAG,"__.__")# %</td></tr>
<tr><td>% of Mailer: </td><td>#NumberFormat(MAILER,"__.__")# %</td></tr>
<tr><td>% of Search Engine: </td><td>#NumberFormat(SEARCH,"__.__")# %</td></tr>
<tr><td>% of Company Colleague: </td><td>#NumberFormat(CO,"__.__")# % </td></tr>
<tr><td>% of Other: </td><td>#NumberFormat(OTHER,"__.__")# %</td></tr>
<tr><td>USA Respondents: #GetQuery.state#</td><td>#NumberFormat(USPER,"__.__")#%</td><tr>
<tr><td>International Respondents: #FOREIGN#</td><td>#NumberFormat(FORPER,"__.__")#%</td></tr>

</cfoutput>
</table>

Comments

  1. 01 Jan 1999 at 00:00

    This thread is for discussions of Create a Percentage Table.

Leave a comment

Sign in or Join us (it's free).

Julia Lynne Green I have been a ColdFusion and ASP programmer for UPS in Watertown Massachusetts for the past two years, and for my own business, Julia Computer Consulting. I believe ColdFusion is the way of the fu...
AddThis

Related podcasts

  • Crawlable Flash, Concurrent Python, Smart Robots.txt and more

    Mixed topics today Adobe works with Google, Yahoo and others to make Flash apps crawlable. Reddit.com open sources their codebase "Smart" robots.txt files - do you use them? Bruce Eckel article on concurrent Python with Twisted Railo - open source ColdFusion Cognifty - new PHP framework...

Events coming up

  • Jul 17

    Orange County ColdFusion User Group

    Santa Ana, United States

    Orange County ColdFusion User Group, or OCCFUG, is an official Adobe User Group, and benefits from Adobe-sponsored software bundle giveaways twice a year. The focus of this Special Interest Group is on Adobe ColdFusion, helping beginers and experts alike. Steve Farwell is the Manager of this SIG, and Scott Bennett is the Co-Manager. OCCFUG meets on the third Thursday of every month, and the fee for non-OCMMA members is $10, or $5 for students.

Want to stay in touch with what's going on? Follow us on twitter!