| Dynamically Generating HTML Table Columns & Rows by: James Harvey |
I've written this tutorial, because I had a need to do exactly what the title suggests. I needed to dynamically generate a table with Columns and Rows, based off of a CFQUERY results. Well, this is the fruit of my labors, and I hope it assists others as well.
Introduction:
In this example you are treating your recordset as though it was a structure.
The first loop will give you your rows and the nested loop will give you your cells.
To change the number of columns in the table you will modify the variable NumberOfColumns.
The Script:
<cfquery name="parks" datasource="cfdocexamples">
select top 7 parkName, parkType, city, state from parks order by parkName
</cfquery>
<cfset NumberOfColumns = 5>
<cfset idx2Counter = 1>
<cfset addTo = parks.RecordCount MOD NumberOfColumns>
<!---\\ If you have a remainder you need to add 1 more row. //--->
<cfif addTo GT 0>
<cfset addTo = 1>
</cfif>
<table border="1">
<cfloop from="1" to="#(parks.RecordCount/NumberOfColumns) + addTo#" index="idx">
<tr>
<cfloop from="1" to="#NumberOfColumns#" index="idx2">
<td valign="top">
<cfoutput>
<!---\\This is the content of the Cell Pulled from the database query above//--->
<cfif Len(parks.parkName[idx2Counter])>
#parks.parkName[idx2Counter]#<br>
#parks.parkType[idx2Counter]#<br>
#parks.city[idx2Counter]#, #parks.state[idx2Counter]#
<cfelse>
</cfif>
<!---\\Now We end out content output//--->
</cfoutput>
</td>
<cfset idx2Counter = idx2Counter + 1>
</cfloop>
</tr>
</cfloop>
</table>
This will now generate a table with 5 columns and X number of rows.
Enjoy!
-James
This Tutorial will show you how to display tag restricitons with Sandbox Security enabled.
Many times we need a quick and easy way of importing data into our website databases. The CSV file format is one of the defacto standards for moving data between databases easily. Virtually all databases allow exported to CSV format. And virtually all database support importing a CSV formatted file. So why use Coldfusion to do this mundane task? Simply put it is database independant - in this example I created a simple script that reads a CSV file and inserts the records into a matched mySQL table. When I first started looking at this I was surprised that I could find very little of how to achieve this. So now that I have it worked out I thought I could share this little piece...
This is a Spry & Coldfusion tutorial for making phone calls via the internet. This Tutorial has a catch however, it's for use with Vonage's 'Click-to-Call' service.
In this tutorial, I'm showing you a working method for URL Rewriting using ColdFusion, and a ColdFusion CFC.
You'll be able to have your old urls like: http://yoursite.com/index.cfm?var1=1&var2=2
to be viewed and displayed as: http://yoursite.com/index.cfm/var1/1/var2/2/
This tutorial shows you how to gather and store user statistics, including Browser, Browser Version, Screen Width, Color Depth, Screen Height, Bit Rate and User Environment. Includes Browser Detection for IPhone, Blackberry, and Android-based mobile devices...
In FireFox, you can dynamically set the EncType of a form element to be "multipart/form-data" for file uploads; however, this does not work in Internet Explorer (IE). Apparently in IE, you have to set the "encoding" of the form rather than the "enctype". The good news is, you can set both values without concern and this will take care of the problem:
This Tutorial Will show you how to generate RSS Feeds from a Database Query and have those feeds made into a Compliant RSS 2.0 Feed Requires ColdFusion 8, will not work on earlier version of Coldfusion.
In this tutorial I'll show you how to optimze your database tables in MySQL (The script is very similiar for SQL Server) by using CFQUERY in a coldfusion page.
It's becoming more and more common that Users are accessing your website from a mobile web browser (like that from an IPhone, Blackberry, Android or other mobile device). It's also becoming more prevelant that you need to start supporting and developing for the mobile platforms. But how would you begin?
This tutorial will help you out.
In this tutorial, I'm going to show you how easy it is to create a username check utility directly inside your web-based form, using JQuery & ColdFusion.
With AJAX applications giving us a lot more power than an "old school" web 1.0 page, it isn't unusual for someone to just sit on one page and fire off various operations that use HTTP to fetch and present data. This works fine until you leave the site alone for too long and your session times out. (I'm assuming most folks use a time based session, much like how ColdFusion works.) The question is - what happens in your current AJAX based application when a user's session times out?
There is a solution...