<<

Data Handling

Hands On 9

By Simon Free (Bio)
gist

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.