Week 2 IBS 685. Project Site Upload assignments to your project site that you will create for IBS 685.

Slides:



Advertisements
Similar presentations
PHP: Date() Function The PHP date() function formats a timestamp to a more readable date and time.
Advertisements

Introducing JavaScript
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
The Web Warrior Guide to Web Design Technologies
Chapter 51 Scripting With JSP Elements JavaServer Pages By Xue Bai.
Lecture 2 Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
Introduction to C Programming
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
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.
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
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
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"
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
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.
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 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
LECTURE 1 INTRODUCTION TO PL/SQL Tasneem Ghnaimat.
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.
Recognizing PL/SQL Lexical Units. 2 home back first prev next last What Will I Learn? List and define the different types of lexical units available in.
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.
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.
1 JavaScript in Context. Server-Side Programming.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
PHP Form Processing * referenced from
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
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.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
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
Introduction to JavaScript
A second look at JavaScript
PHP.
Web DB Programming: PHP
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Introduction to JavaScript
Tutorial 10: Programming with javascript
Presentation transcript:

Week 2 IBS 685

Project Site Upload assignments to your project site that you will create for IBS 685

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.

Commenting Your Code In order to ensure maintability of your applications, you should always comment your code in as much detail as possible. A better way is to document the code as you write it, using CFML comments. –You may be familiar with HTML comments: – –CF comments are similar, but use three dashes instead of two: – –CF comments are not sent back to the browser, but are processed out and omitted from the page. In this way you can be sure that users will not be able to read your sensitive comments.

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”.

Result Sets

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.

Movie List Page

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#

The output of the previous code would be: 1.Beans R Us 2.The Buzz 3.Coffee Galore 4.Perk Plus 5.Café Colombian 6.Jumpin Java 7.Coffee The whole Bean 9.Roast Resellers