
132
Chapter 8 Handling Complex Data with Structures
<input type="Submit" value="OK">
</form>
</body>
</html>
Example file addemployee.cfm
<!--- This file is an example of a custom tag used to add employees.
Employee information is passed through the employee structure (the
empinfo attribute). For databases that do not support automatic key
generation, you must also add the Emp_ID. --->
<cfif structisempty(attributes.empinfo)>
<cfoutput>Error. No employee data was passed.</cfoutput>
<cfexit method="ExitTag">
<cfelse>
<!--- Add the employee --->
<!--- If auto key generation is not supported,
you must also add the Emp_ID --->
<cfquery name="AddEmployee" datasource="cfsnippets">
INSERT INTO Employees
(FirstName, LastName, Email, Phone, Department)
VALUES
<cfoutput>
(
’#StructFind(attributes.empinfo, "firstname")#’ ,
’#StructFind(attributes.empinfo, "lastname")#’ ,
’#StructFind(attributes.empinfo, "email")#’ ,
’#StructFind(attributes.empinfo, "phone")#’ ,
’#StructFind(attributes.empinfo, "department")#’
)
</cfoutput>
</cfquery>
</cfif>
<cfoutput><hr>Employee Add Complete</cfoutput>
Looping through structures
You can loop through a structure to output its contents as illustrated in the following
example. Note that when you enumerate key-value pairs using a loop, the keys
appear in uppercase.
<!--- Create a structure and set its contents --->
<cfset departments=structnew()>
<cfset val=StructInsert(departments, "John", "Sales")>
<cfset val=StructInsert(departments, "Tom", "Finance")>
<cfset val=StructInsert(departments, "Mike", "Education")>
<!--- Build a table to display the contents --->
<cfoutput>
Содержание COLDFUSION 5-DEVELOPING
Страница 1: ...Macromedia Incorporated Developing ColdFusion Applications MacroMedia ColdFusion 5 ...
Страница 58: ...38 Chapter 3 Querying a Database ...
Страница 134: ...114 Chapter 7 Updating Your Database ...
Страница 210: ...190 Chapter 10 Reusing Code ...
Страница 232: ...212 Chapter 11 Preventing and Handling Errors ...
Страница 238: ...218 Chapter 12 Using the Application Framework ...
Страница 262: ...242 Chapter 12 Using the Application Framework ...
Страница 278: ...258 Chapter 13 Extending ColdFusion Pages with CFML Scripting ...
Страница 320: ...300 Chapter 15 Indexing and Searching Data ...
Страница 336: ...316 Chapter 16 Sending and Receiving E mail ...
Страница 374: ...354 Chapter 18 Interacting with Remote Servers ...