Week 5 IBS 520. ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

Java Script Session1 INTRODUCTION.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
The Web Warrior Guide to Web Design Technologies
Introduction to C Programming
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Chapter 2 Basic Elements of Fortan
Week 2 IBS 685. Static Page Architecture The user requests the page by typing a URL in a browser The Browser requests the page from the Web Server The.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable,
Chapter 2: Introduction to C++.
Introduction to C Programming
Week 2 IBS 685. Project Site Upload assignments to your project site that you will create for IBS 685.
Basic Elements of C++ Chapter 2.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
Lecture Note 3: ASP Syntax.  ASP Syntax  ASP Syntax ASP Code is Browser-Independent. You cannot view the ASP source code by selecting "View source"
Bordoloi and Bock CURSORS. Bordoloi and Bock CURSOR MANIPULATION To process an SQL statement, ORACLE needs to create an area of memory known as the context.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
1 PHP Variables. 2 What is a variable? A variable is something that can be changed – a thing that can take on any value from a possible set of values.
Numeric Variables Visual Basic for Applications 6.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
1 JavaScript in Context. Server-Side Programming.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Input, Output, and Processing
JSTL, XML and XSLT An introduction to JSP Standard Tag Library and XML/XSLT transformation for Web layout.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Improving Database Performance Derrick Rapley
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
CF101: Welcome to ColdFusion Simon Horwith CTO, Etrilogy Ltd.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
XP Tutorial 8 Adding Interactivity with ActionScript.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
CST336, Dr. Krzysztof Pietroszek Week 2: PHP. 1.Introduction to PHP 2.Embed PHP code into an HTML web page 3.Generate (output HTML) web page using PHP.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Web Database Programming Using PHP
Chapter 6 JavaScript: Introduction to Scripting
CF101: Welcome to ColdFusion
Web Database Programming Using PHP
Variables, Expressions, and IO
JavaScript Syntax and Semantics
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
PHP Introduction.
Intro to PHP & Variables
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Topics Introduction to File Input and Output
Number and String Operations
PHP.
Web DB Programming: PHP
Chapter 2: Introduction to C++.
Topics Introduction to File Input and Output
Presentation transcript:

Week 5 IBS 520

ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own use. To use a variable, name it and assign it a value. When working with variables, you can assign a specific value, such as “7” or “Sue”

Variable Naming All CF variables must be named using the following rules: –Use one word –Do not use spaces –Begin with a letter –Use only letters, numbers and underscore –Do not use special characters

Variable Prefixes There are many types of variables in CF. Each variable has it is own scope –Where it exists –How long it exist for –Where the variable value is stored. LocalQueryForm URLSessionCookie

Creating Local Variables with The tag is used to initialize the value of a variable. You set the value as being equal to an expression, which can contain variables, functions and operators. The syntax for this tag is: The result is a variable than can be accessed on the current page only. This is known as a local variable. The scope or when a variable can be accessed is the page. In the following examples, the variables have specific values: In the example above we are assigning literal values to the variable. All literal values are surrounded by double quotes

Creating Local Variables with In this example, the variable draws its value from two other variables: In the next example, ColdFusion uses the values of the firstname and lastname variables to set the value for the fullname variable in the last line of code. The ampersand (&) string operator joins the variables, and the space surrounded by double quotation marks (" ") adds a space between the variables. The result would be: Sue Smith

Referencing Variables To reference a local variable’s value, use the variables prefix. In this way, you can avoid confusing different components in your code and make your code easier to maintain. variables.firstname Notice that you reference variables in the expression (right hand side of the equal sign) without using double quotes. CF assumes that non quoted values are variables and will return the value of those variables in assignment. If you attempt to perform the following assignment, CF would attempt to convert Firstname and LastName to numeric values for addition, which would result in a runtime error. As you can see by the following example you can perform arithmetic operations on a variable that is set as a string.

Displaying Variable Output Use the tag to bracket a block of code for CF processing. CF preprocesses all code that falls between and tags and passes all other code unprocessed, to the Web Server. To output the value of a variable rather than its name: Surround the variable name with pound signs (##) Place the name between and tags. The sysntax for the tag is: [CF processing instructions] Here is the example of defining variables with the tag outside the code block: #variables.fullname# The output of this code is: Teddy Bear

CF Functions CFML is made up of two primary language elements –Tags – perform operations such as accessing a database, evaluating a condition –Functions- Return (possibly process) data and do things such as getting the current date and time, converting text to uppercase, and rounding a number to its nearest integer.

CF Functions #Now()# is an instruction telling CF to execute a function named Now()- –a function that returns the current date and time. e.g.{ts ‘ :40:23’} What happens –If no pound signs? –If put outside the cfoutput tag?

Usage Examples Call a function to return a value: Function() –#Now()# –Returns {ts ‘ :40:23’} Nesting functions:Function1(Function2(data)) –DateFormat(Now()) –Returns 03-Oct-97

CF Functions Format of that date function is not entirely readable. Another function, DateFormat( ) can help here. DateFormat () role is to format dates so they are readable.

CF Functions DateFormat is an example of a function that accepts (and requires) that data must be passed to it – after all it needs to know which date you want to format to display. #DateFormat(Now())# tells CF to format the date returned by the Now() function.

NEST(le) Passing a function as a parameter to another function is referred to as NESTING. The Now() function is said to be NESTED in the DateFormat() function.

DateFormat() DateFormat() takes second optional attribute: –A format mask used to describe the output format. #DateFormat(Now(), “MMMM-DD-YY”)# #DateFormat(Now(), “MM-DD-YY”)# #DateFormat(Now(), “DDD,MMMM DD-YYYY”)# Parameters passed to a function are always separated by comma.

Publishing Database Content The tag wraps around the SQL statement. This returns the result set to CF. Select distributor. Distributor_ID, Distributor. Distributor_Name From Distributor Order By Distributor. Distributor_ID

DATASOURCE Using the datasource attribute, the tag will use the connection parameters set up in the administrator. This is the only required attribute to Select distributor. Distributor_ID, Distributor. Distributor_Name From Distributor Order By Distributor. Distributor_ID

NAME The query returns a result set identified by the NAME attribute. This name will be used to point to the result set in memory after the database returns the requested data to CF. Select distributor. Distributor_ID, Distributor. Distributor_Name From Distributor Order By Distributor. Distributor_ID As a naming convention you may want to name all your queries with a prefix of “q”.

Displaying Database Data Use the tag to: –Output dynamic variable values –Loop through and output a result set –Use to display the values returned by a query. Bearing in mind what you learned about displaying the values of variables. –Consider the following code:

Special Information Returned With Queries For each query you execute, CF also stores special information about the query. This information is stored in variables. These variables are available to you after each query and are valid until the end of the page process.

RecordCount RecordCount contains the total number of records returned by the query. Number of rows returned: #queryname.recordcount#

CurrentRow CF assigns a sequential number to each row returned. You can use the variable CurrentRow to print out this number. As you print out each row, you can use CurrentRow to display the current row and recordCount to display the total number of rows. Row#queryname.currentrow# of #queryname.recordcount#

Execution Time Execution time displays the amount of time spent executing and returning the data generated by the query. Access this attribute by using: cfquery.ExecutionTime

CFQUERY

It is a very simple way to reuse code. You put the common code in a separate file and call it using the tag. When Coldfusion encounters this tag searches for the included page. Brings it inline in the processing page and continues processing. The syntax for this tag is You can create common code in a template and use the tag to insert the template’s content wherever you need it. This can be a single line of code or an entire document. The application referencing the included application is referred to as a calling page. The included application is referred to as an included page.

Uses of the tag: Including toolbars on each page Including common headers and footers on each page Including any reusable content.

Mypage.cfm … … Template.cfm Included text here Mypage.cfm …. Included text here ….

Typeless (Not definable) All CF variables are typeless, which means you do not need to identify the type of the data(Such as numbers or dates.) that the variable stores. Behind the scenes CF stores all the values as strings. When variables are accessed and expected to be of a certain data type (such as attempting to perform arithmetic operations on a variable) they are “cast” into the expected type.

Referencing Variables To reference a local variable’s value, use the variables prefix. Notice that you reference variables in the expression (right hand side of the equal sign) without using double quotes.

Displaying Database Data Select distributor. Distributor_ID, Distributor. Distributor_Name From Distributor Order By Distributor. Distributor_ID # Distributor_ID # #Distributor_Name# The above code will not work. To reference query results, you must specify the query result set explicitly. Do this by using Q_getdist prefix on each variable. Note that “q_getdist” is the name of the query in the above example. # q_getdist.Distributor_ID # # q_getdist.Distributor_Name# The output of the above code would be: 1 Beans ‘R Us Notice that only the first row of the result set is displayed. To show all rows returned, add the query attribute to the tag. The syntax is ……. The QUERY attribute changes the into an iterative loop that will execute the number of rows returned in the assignmed query. This syntax will return all rows in the Q_getdist query. Use an HTML tag to put each row on a different line # q_getdist.Distributor_ID # # q_getdist.Distributor_Name#