In this hands on, we will do a simple database call and output the data.
Tags Used: <cfset>, <cfquery>, <cfloop>
- Open up the /www/resume.cfm file in your code editor.
-
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
-
On the next line enter the following SQL code:
SELECT name FROM skillset ORDER BY name DESC
- On the next line, write a closing </cfquery> tag.
-
Your code should look similar to this:
<cfquery name="mySkillset" datasource="learncfinaweek"> SELECT name FROM skillset ORDER BY name DESC </cfquery>
- Please note that the data source you are using was created during the initial setup process for you.
-
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
- Inside the <cfloop> tag, replace all references to skill with #mySkillset.name#.
-
Your code should look similar to this:
<cfloop query="mySkillset"> <li class="#mySkillset.name#" id="#mySkillset.name#">#mySkillset.name#</li> </cfloop>
- Open up your browser and navigate to the /www/resume.cfm page. Confirm that the Skills are still displaying.