Skip to content

Instantly share code, notes, and snippets.

@learncfinaweek
Created November 20, 2012 21:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save learncfinaweek/4121143 to your computer and use it in GitHub Desktop.
Save learncfinaweek/4121143 to your computer and use it in GitHub Desktop.
Data Handling - Hands On 9

In this hands on, we will do a simple database call and output the data.

Tags Used: <cfset>, <cfquery>, <cfloop>

  1. Open up the /www/resume.cfm file in your code editor.
  2. First, replace the list with a call to the database. On line 1, replace the <cfset> tag with an open <cfquery> tag with the following attributes:
    • name: mySkillSet
    • datasource: Learncfinaweek
  3. On the next line enter the following SQL code:
    SELECT
    	name
    FROM
    	skillset
    ORDER BY
    	name DESC
    
  4. On the next line, write a closing </cfquery> tag.
  5. Your code should look similar to this:
    <cfquery name="mySkillset" datasource="learncfinaweek">
    	SELECT
    		name
    	FROM
    		skillset
    	ORDER BY
    		name DESC
    </cfquery>		
    
  6. Please note that the data source you are using was created during the initial setup process for you.
  7. Now that you have a query, you need to update the loop to accept the query rather than the list. Locate the opening <cfloop> tag on or around line 120 and replace its attributes with:
    • query: mySkillset
  8. Inside the <cfloop> tag, replace all references to skill with #mySkillset.name#.
  9. Your code should look similar to this:
    <cfloop query="mySkillset">
    	<li class="#mySkillset.name#" id="#mySkillset.name#">#mySkillset.name#</li>
    </cfloop>	
    
  10. Open up your browser and navigate to the /www/resume.cfm page. Confirm that the Skills are still displaying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment