Web Technology Study Material GTU - 23042016 - 032646AM PDF
Web Technology Study Material GTU - 23042016 - 032646AM PDF
Web Technology Study Material GTU - 23042016 - 032646AM PDF
Concept of WWW.
WWW is stands for World Wide Web.
The World Wide Web (WWW) is a global information medium which users can read and write
via computer connected to the internet.
The Web, or World Wide Web, is basically a system of Internet servers that support specially
formatted documents. The documents are formatted in a markup language called HTML
(Hypertext Markup Language) that supports links to other documents, as well as graphics,
audio, and video files.
In short, World Wide Web (WWW) is collection of text pages, digital photographs, music files,
videos, and animations you can access over the Internet.
Web pages are primarily text documents formatted and annotated with Hypertext Markup
Language (HTML). In addition to formatted text, web pages may contain images, video, and
software components that are rendered in the user's web browser as coherent pages of
multimedia content.
The terms Internet and World Wide Web are often used without much distinction. However,
the two are not the same.
The Internet is a global system of interconnected computer networks. In contrast, the World
Wide Web is one of the services transferred over these networks. It is a collection of text
documents and other resources, linked by hyperlinks and URLs, usually accessed by web
browsers, from web servers.
There are several applications called Web browsers that make it easy to access the World
Wide Web; For example: Firefox ,Microsoft's Internet Explorer, Chrome Etc.
Users access the World-Wide Web facilities via a client called a browser, which provides
transparent access to the WWW servers. User can access WWW via two way such us :
History of WWW:
Tim Berners-Lee, in 1980 was investigating how computer could store information with
random links. In 1989, while working at European Particle Physics Laboratory, he proposed to
idea of global hypertext space in which any network-accessible information could be referred
to by single universal Document Identifier. After that in 1990, this idea expanded with
further program and knows as World Wide Web.
Internet and WWW
The Internet, linking your computer to other computers around the world, is a way of
transporting content. The Web is software that lets you use that contentor contribute your
own. The Web, running on the mostly invisible Internet, is what you see and click on in your
computers browser.
What is The Internet?
The Internet is a massive network of networks, a networking infrastructure. It connects
millions of computers together globally, forming a network in which any computer can
communicate with any other computer as long as they are both connected to the Internet.
Information that travels over the Internet does so via a variety of languages known as
As mentioned, whenever you enter a URL in the address box of the browser, the browser
translates the URL into a request message according to the specified protocol; and sends the
request message to the server.
For example, the browser translated the URL http://www.test101.com/doc/index.html into
the following request message:
Here,Step by step communication between client and server mention into followingfigure.
Web Browser
Web browser is a client, program, software or tool through which we sent HTTP request to
web server. The main purpose of web browser is to locate the content on the World Wide Web
and display in the shape of web page, image, audio or video form.
Web Server
Web server is a computer system, which provides the web pages via HTTP (Hypertext Transfer
Protocol). IP address and a domain name is essential for every web server.
Whenever, you insert a URL or web address into your web browser, this sends request to the
web address where domain name of your URL is already saved. Then this server collects the all
information of your web page and sends to browser, which you see in form of web page on
your browser.
Lot of web server software is available in the market in shape of NCSA, Apache, Microsoft and
Netscape. Storing, processing and delivering web pages to clients are its main function. All the
communication between client (web browser) and server takes place via HTTP.
Here, we can easily understand concept of web browser and web server by following figure.
Display Resolution
Display resolution is another important factor affecting the Web page design, as we do not have any
control on display resolution of the monitors on which user views our pages.
Display or screen resolution is measured in terms of pixels and common resolutions are 800 X 600
and 1024 X 786.
We have three choices for Web page design.
o Design a web page with fixed resolution.
o Make a flexible design using HTML table to fit into different resolution.
o If the page is displayed on a monitor with a higher resolution, the page is displayed on left-
hand side and some part on the right-hand side remains blank. We can use centered design
to display page properly.
o (Not For Exam) Ideally we should use some frameworks for designing like
Bootstrap/Material design.
Locating Information
Webpage is viewed on a computer screen and the screen can be divided into five major areas such
as center, top, right, bottom and left in this particular order.
The first major area of importance in terms of users viewing pattern is the center, then top, right,
bottom and left in this particular order.
Sitemap
Many a times Web sites are too complex as there are a large number of sections and each section
contains many pages.
It becomes difficult for visitors to quickly move from one part to other.
Once the user selects a particular section and pages in that section, user gets confused about where
he/she is and where to go from there.
To make it simple, keep your hierarchy of information to few levels or provide the navigation bar on
each page to jump directly to a particular section.
HTML
What is HTML?
Stands for Hypertext Markup Language.
Most documents that appear on the World Wide Web were written in HTML.
HTML is a markup language, not a programming language. In fact, the term HTML is an acronym that
stands for Hypertext Markup Language.
We can apply this markup language to your pages to display text, images, sound and movie files, and
almost any other type of electronic information.
We use the language to format documents and link them together, regardless of the type of
computer with which the file was originally created.
HTML Elements
An element consists of three basic parts: an opening tag, the element's content, and finally, a closing
tag.
<p> - opening paragraph tag
Element Content - paragraph words
</p> - closing tag
Every (web) page requires four critical elements: the html, head, title, and body elements.
1. <html> Element...</html>
o <html> begins and ends each and every web page.
o Its purpose is to encapsulate all the HTML code and describe the HTML document to the
web browser.
<html></html>
2. <head> Element
o The <head> element is "next" as they say. As long as it falls somewhere between your <html>
tag and your web page content (<body>).
o The head functions "behind the scenes." Tags placed within the head element are not directly
displayed by web browsers.
o We will be placing the <title> element here.
o Other elements used for scripting (JavaScript) and formatting (CSS) will eventually be introduced
and you will have to place them within your head element.
<html>
<head>
</head>
</html>
HTML Tags
o A web browser reads an HTML document top to bottom, left to right.
o Each time the browser finds a tag, it is displayed accordingly (paragraphs look like paragraphs,
tables look like tables, etc).
o Tags have 3 major parts: opening tag(s), content(s), and closing tag(s).
o Recall that a completed tag is termed an element.
<html><body>
<h1>This is heading 1</h1><h2>This is heading 2</h2><h3>This is heading 3</h3>
<h4>This is heading 4</h4><h5>This is heading 5</h5><h6>This is heading 6</h6>
</body></html>
3. Line Breaks
o Line breaks are different then most of the tags we have seen so far. A line break ends the line
you are currently on and resumes on the next line.
Prof. Arjun Bala, CE Department | 2160708 Web Technology 2
3 - HTML
<p>Darshan<br />
Computer<br /></p>
HTML Lists
o There are 3 different types of lists.
o A <ol> tag starts an ordered list, <ul> for unordered lists, and <dl> for definition lists.
1. <ul> - unordered list; bullets
2. <ol> - ordered list; numbers
3. <dl> - definition list; dictionary
<ol>
<li>Find a Job</li>
<li>Move Out</li>
</ol>
o Start your ordered list on any number besides 1 using the start attribute.
<ol start="4" >
<li>Buy Food</li>
<li>Get a Degree</li>
</ol>
o There are 4 other types of ordered lists. Instead of generic numbers you can replace them with
Roman numerals or letters, both capital and lower-case. Use the type attribute to change the
numbering.
<oltype="a">
<oltype="A">
<oltype="i">
<ol type="I">
</ol>
<ul>
<li>Milk</li>
<li>Chocolate</li>
</ul>
<oltype="square">
<ol type="disc">
<oltype="circle">
</ol>
<dl>
<dt><b>Fromage</b></dt>
<dd>French word for cheese.</dd>
<dt><b>Voiture</b></dt>
<dd>French word for car.</dd>
</dl>
4. HTML Nested Lists
o You can also nest one list within another, so you could make an unordered list inside a
<html>
<ol>
<li> Clear out garage</li>
<ul>
<li> Tomatoes</li>
</ul>
<li> repair fence </li>
</ol>
</html>
numbered one:
<body bgcolor=red>
<font color=red>
<body bgcolor=rgb(72,0,0)>
<font color=rgb(72,0,0)>
<body bgcolor=#ffff00>
<font color=#ffff00>
2. Font Color
o Set the color of your font with color.
3. Font Face
o Choose a different font face using any font you have installed.
HTML Code:
<html><body>
<basefont size="2" color="green"><p>This paragraph has had its font...</p>
</basefont>
</body></html>
Internal - href="#anchorname"
Local - href="../pics/picturefile.jpg"
Global - href=http://www.xyz.com/
Link Targets
o The target attribute defines whether to open the page in a separate window, or to open the link
in the current browser window.
HTML Code:
target=" _blank" Opens new page in a new browser
window
Anchors
o To link to sections of your existing page a name must be given to the anchor.
o In the example below, we've created a mini Table of Contents for this page.
o By placing blank anchors just after each heading, and naming them, we can then create
reference links to those sections on this page as shown below.
o First, the headings of this page contain blank, named anchors. They look like this.
o Now create the reference links, placing the # symbol followed by the name of the anchor in the
href of the new link.
HTML Images
o Use the <img /> tag to place an image on your web page.
<imgsrc="sunset.gif" />
1. Image src
o Above we have defined the src attribute.
o Src stands for source, the source of the image or more appropriately, where the picture file is
located.
o There are two ways to define the source of an image. First you may use a standard URL.
(src=http://www.Xyz.com/pics/htmlT/sunset.gif) As your second choice, you may copy or upload
the file onto your web server and access it locally using standard directory tree methods.
(src="../sunset.gif")
o The location of this picture file is in relation to your location of your .html file.
URL Types:
Local Src Location Description
src="sunset.gif" picture file resides in same directory as .html file
2. Alternative Attribute
o The alt attribute specifies alternate text to be displayed if for some reason the browser cannot
find the image, or if a user has image files disabled.
5. Images as Links
o Images are very useful for links and can be created with the HTML below.
<a href="http://www.xyz.com/"><imgsrc="sunset.gif"></a>
HTML Forms
o A form will take input from the viewer and depending on your needs, you may store that data
into a file, place an order, gather user statistics, register the person to your web forum, or
maybe subscribe them to your weekly newsletter.
Making a Form
o <form> is main tag to build a form.
o It has a few optional attributes too. Below is an example of the form element.
o The action attribute tells the HTML where to send the collected information, while the method
attribute describes the way to send it.
Type of Input
o The main tag for collecting information from the user is <input>.
o The tag itself contains a name attribute, so that we can refer to the input by a name, and the size
of the entry box in characters.
o There are quite few different types of input to choose from:
o <input type=text/> this is the default input type and accepts characters and numbers into a
text box. It can also have a value attribute attached to it, which will give it an initial value.
o <input type=password/> this is similar to the above text box but anything that is typed cannot
be seen; instead an asterisk is printed to cover up the entry. As the name suggests, this is used
for password entry.
o <input type=checkbox/> this gives a box that can be toggled between checked and unchecked.
It can initially be set to one or the other with checked=checked.
o <input type=radio/> this is similar to checkbox but in group of radio buttons only one can be
selected at a time. This can also have an initial checked state on one of the radio buttons.
o <input type=file/>This will give a box to allow you to choose a file similar to when you open or
save files usually on your machine. It can be used to select a file on the local machine for upload
to a server.
HTML Tables
o The <table> tag is used to begin a table. Within a table element are the <tr> (table rows) and
<td> (table columns) tags.
<table border="1">
<tr><td>Row 1 Cell 1</td><td>Row 1 Cell 2</td></tr>
<tr><td>Row 2 Cell 1</td><td>Row 2 Cell 2</td></tr>
</table>
o And now we will change the cellpadding of the table and remove the cellspacing from the
previous example.
1. Name:
Thename attribute specifies thenameofaformwhichisusedtoreferenceelementsinaJavaScript.
2. Action:
The required action attribute specifies where to send the formdata when a form
issubmitted.
<form action="URL"> Value : URL
Description : Where to send the form data.
3. Method :
The method attribute specifies how to send formdata (the formdata is sent to the
pagespecified in the action attribute).
<form method="get|post">
Value : get
Description : Default. Appends the formdata to the URL in name/value pairs:
URL?name=value&name=value
Value : post
Description : Sends the formdata as an HTTP post transaction.
4. Target
The target attribute specifies a name or a keyword that indicates where to display the
response that is received after submitting the form.
<form target="_blank|_self|_parent|_top|framename">
Value Description
_blank Theresponseisdisplayedinanewwindowortab
_self Theresponseisdisplayedinthesameframe(thisisdefault)
_parent Theresponseisdisplayedintheparentframe
_top Theresponseisdisplayedinthefullbodyofthewindow
framename Theresponseisdisplayedinanamedframe
<select>
<optgroup label="Swedish Cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</optgroup>
<optgroup label="German Cars">
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</optgroup>
</select>
(2)<span>:
The <span> tag is used to group inlineelements in a document.
The <span> tag provides no visual change by itself.
The <span> tag provides a way to add a hook to a part of a text or a part of a document.
When the text is hooked in a <span> element you can add styles to the content, or manipulate
thecontent with for example JavaScript.
<p>Mymotherhas<spanstyle="color:lightblue">lightblue</span>eyes.</p>
Introduction to HTML5
The DOCTYPE declaration for HTML5 is very simple:
<!DOCTYPE html>
The character encoding (charset) declaration is also very simple:
<meta charset="UTF-8">
New HTML5 Elements:
o New semantic elements like <header>, <footer>, <article>, and <section>.
o New form control attributes like number, date, time, calendar, and range.
o New graphic elements: <svg> and <canvas>.
o New multimedia elements: <audio> and <video>.
o Elements Removed in HTML5
The following HTML4 elements have been removed from HTML5:
<acronym> <abbr>
<applet> <object>
<basefont> CSS
<big> CSS
<center> CSS
<dir> <ul>
<font> CSS
<frame>
<frameset>
<noframes>
<strike> CSS
<tt> CSS
What is CSS?
CSS stands for Cascading Style Sheets
Styles define how to display HTML elements
External Style Sheets can save a lot of work
External Style Sheets are stored in CSS files
Importance of CSS
CSS defines HOW HTML elements are to be displayed.
Styles are normally saved in external .css files. External style sheets enable you to change the
appearance and layout of all the pages in a Web site, just by editing one single file.
CSS Syntax
A CSS rule has two main parts: a selector, and one or more declarations:
The id Selector
The id selector is used to specify a style for a single, unique element.
The id selector uses the id attribute of the HTML element, and is defined with a "#".
The style rule below will be applied to the element with id="para1":
#para1
{ text-align:center; color:red; }
.center {text-align:center;}
We can use more than one class in a single element
Explain different ways to write the CSS. / Explain CSS with all types. / Enlist
and explain methods of using CSS in web page.
There are three ways of inserting a style sheet:
o External style sheet
o Internal/Embedded style sheet
o Inline style
1. External Style Sheet
o When using CSS it is preferable to keep the CSS separate from your HTML.
o Placing CSS in a separate file allows the web designer to completely differentiate between
content (HTML) and design (CSS).
o External CSS is a file that contains only CSS code and is saved with a ".css" file extension.
o This CSS file is then referenced in your HTML using the <link> instead of <style>.
File Creation
o Open up notepad.exe, or any other plain text editor and type the following CSS code.
body{ background-color: gray;} p { color: blue; }h3{ color: white; }
o Save the file as a CSS (.css) file.
o Name the file "test.css" (without the quotes). Now create a new HTML file and fill it with
the following code.
<html><head>
<link rel="stylesheet" type="text/css" href="test.css" /></head>
<body>
<h3> A White Header </h3>
<p> This paragraph has a blue font.
The background color of this page is gray because we changed it with CSS! </p>
</body></html>
2. Internal/Embedded CSS
o This type of CSS is only for Single Page.
o When using internal CSS, we must add a new tag, <style>, inside the <head> tag. The
HTML code below contains an example of <style>'s usage.
<html><head>
<style type="text/css"></style>
</head><body>
<p>Your page's content!</p></body>
</html>
3. Inline CSS
o It is possible to place CSS right in your HTML code, and this method of CSS usage is
referred to as inline css.
o Inline CSS has the highest priority out of external, internal, and inline CSS.
o This means that you can override styles that are defined in external or internal by using
inline CSS.
o If you want to add a style inside an HTML element all you have to do is specify the desired
CSS properties with the style HTML attribute.
<html><head>
<link rel="stylesheet" type="text/css" href="test.css" /></head>
<body>
<p style="background: blue; color: white;">A new background andfont color with
inline CSS</p></body>
</html>
body {background-image:url('paper.gif');}
3. Background Image Repeat
o You can have a background image repeat vertically (y-axis), horizontally (x-axis), in both
directions, or in neither direction.
p {background-image: url(smallPic.jpg); background-repeat: repeat; }
h4 {background-image: url(smallPic.jpg); background-repeat: repeat-y; }
ol {background-image: url(smallPic.jpg); background-repeat: repeat-x; }
ul {background-image: url(smallPic.jpg);background-repeat: no-repeat; }
p { font-variant: small-caps; }}
2. Text Indent
o The text-indentation property is used to specify the indentation of the first line of a text.
p { text-indent: 20px; } h5 { text-indent: 30%; }
3. Text Align
o The text-align property is used to set the horizontal alignment of a text.
p { text-align: right; }
h5{ text-align: justify; }
4. Text Transform
o The text-transform property is used to specify uppercase and lowercase letters in a text.
The top, right, bottom, and left margin can be changed independently using separate properties. A
shorthand margin property can also be used, to change all margins at once.
Value Descriptions
auto The browser calculates a margin
length Specifies a margin in px, pt, cm, etc. Default value is 0px
% Specifies a margin in percent of the width of the
containing element
inherit Specifies that the margin should be inherited from the
parent element
2. Border Width
o The border-width property is used to set the width of the border.
3. Border Color
o The border-color property is used to set the color of the border.
o Border colors can be any color defined by RGB, hexadecimal, or key terms. Below is an
example of each of these types.
4. Border: border-(direction)
o If you would like to place a border on only one side of an HTML element, or maybe have a
unique look for each side of the border, then use border-(direction).
o The direction choices are of course: top, right, bottom, and left. CSS allows you to treat
each side of a border separately from the other three sides.
o Each side can have its own color, width, and style set, as shown below.
p { border-bottom-style: dashed ; border-bottom-color: yellow; border-bottom-width: 5px; }
h4 { border-top-style: double; border-top-color: purple; border-top-width: thick; }
ol { list-style-type: upper-roman; }
ul { list-style-type: circle; }
ul { list-style-image: url("listArrow.gif"); }
ol { list-style-image: url("listArrow2.gif"); }
ul { list-style-position: inside; }
ol { list-style-position: outside; }
Note: "Outside" is actually the default setting for indentation.
a:link {background-color:#B2FF99;}
a:visited {background-color:#FFFF85;}
a:hover {background-color:#FF704D;}
a:active {background-color:#FF704D;}
2. Position Absolute
o With absolute positioning, you define the exact pixel value where the specified HTML
element will appear.
o The point of origin is the top-left of the browser's viewable area, so be sure you are
measuring from that point.
h3 {position: absolute; top: 50px;left: 45px;}
p{position: absolute; top: 75px;left: 75px;}
<body>
<img src="sunset.gif" class="floatLeft"><p>The images are contained with...</p>
<img src="sunset.gif" class="floatRight"><p>This second paragraph has an...</p>
</body>
Introduction to CSS3
CSS3 is the latest standard for CSS.
CSS3 is completely backwards-compatible with earlier versions of CSS.
CSS3 has been split into "modules". It contains the "old CSS specification" (which has been split
into smaller pieces). In addition, new modules are added.
CSS3 Transitions are a presentational effect which allow property changes in CSS values, such as
those that may be defined to occur on :hover or :focus, to occur smoothly over a specified
duration rather than happening instantaneously as is the normal behaviour.
Transition effects can be applied to a wide variety of CSS properties, including background-color,
width, height, opacity, and many more.
Some of the most important CSS3 modules are:
o Selectors
o Box Model
o Backgrounds and Borders
o Image Values and Replaced Content
o Text Effects
o 2D/3D Transformations
o Animations
o Multiple Column Layout
o User Interface
What is JavaScript?
HTML and CSS concentrate on a static rendering of a page; things do not change on the page over
time, or because of events.
To do these things, we use scripting languages, which allow content to change dynamically.
Not only this, but it is possible to interact with the user beyond what is possible with HTML.
Scripts are programs just like any other programming language; they can execute on the client side
or the server.
Embedded JavaScript
JavaScript can be embedded in an HTML document.
To embed it in HTML you must write:
<script type=text/javascript>
</script>
The script tag has effect of the stopping the JavaScript being printed out as well as indentifying the
code enclosed.
The JavaScript can be placed in the head section of your HTML or the body.
<html>
<body>
<script type=text/javascript>
document.write("<h1>This is a heading</h1>");
</script>
</body>
</html>
The Scripts placed in the body section are executed as the page loads and can be used to generate
the content of the page.
As well as the body section, JavaScript can also be placed in the head part.
The advantages of putting a script in there are that it loads before the main body.
External JavaScript
If you want to use the same script on several pages it could be a good idea to place the code in a
separate file, rather than writing it on each.
That way if you want to update the code, or change it, you only need to do it once.
JavaScript Variables
Variables in JavaScript behave the same as variables in most popular programming languages (C,
C++, etc) do, but in JavaScript you don't have to declare variables before you use them.
A variable's purpose is to store information so that it can be used later. A variable is a symbolic name
that represents some data that you set.
When using a variable for the first time it is not necessary to use "var" before the variable name.
Variable names must begin with a letter.
Variable names are case sensitive (y and Y are different variables).
var x=5;
var y=6;
var z=x+y;
You can declare many variables in one statement. Just start the statement with var and separate the
variables by comma:
var name="Doe", age=30, job="carpenter";
var name="Doe",
age=30,
job="carpenter";
JavaScript Operators
Operators in JavaScript are very similar to operators that appear in other programming languages.
The definition of an operator is a symbol that is used to perform an operation.
Most often these operations are arithmetic (addition, subtraction, etc), but not always.
Assignment Equivalent to
X+=Y X=X+Y
X-=Y X=X-Y
X*=Y X=X*Y
X/=Y X=X/Y
X%=Y X=X%Y
JavaScript Array
An array is a special variable, which can hold more than one value at a time.
The Array object is used to store multiple values in a single variable.
An array can be created in three ways.
The following code creates an Array object called myCars.
1. Regular
varmyCars=new Array();
myCars[0]="Saab";
myCars[1]="Volvo";
myCars[2]="BMW";
2. Condensed
varmyCars=new Array("Saab","Volvo","BMW");
3. Literal
varmyCars=["Saab","Volvo","BMW"];
Access an Array
You refer to an element in an array by referring to the index number.
This statement access the value of the first element in myCars.
var name=myCars[0];
JavaScript Functions
A function is a section of code that is separate from the main program.
It is defined once but can be invoked many times.
A function can be passed as parameters so that they can be used and a value can be returned back.
There are some functions already built in to JavaScript, such as the Math.cos() function, which
calculates the cosine of an angle.
An example function could be:
functionmultByTen(x)
{
return x*10;
}
This can then be invoked by using the functions name complete with any parameters you want to
pass:
mysum=multByTen(3)
<html><body>
<script type=text/javascript>
var z= multXbyY(10,15);
document.write(The result is +z);
functionmultXbyY(x,y) {
document.write(x is +x);
document.write(y is +y);
return x*y;
}
</script>
</body></html>
JavaScript Conditions
Conditional statements are used to perform different actions based on different conditions.
In JavaScript we have the following conditional statements:
o if statement - use this statement to execute some code only if a specified condition is true
o if...else statement - use this statement to execute some code if the condition is true and
another code if the condition is false
o if...else if....else statement - use this statement to select one of many blocks of code to be
executed
o switch statement - use this statement to select one of many blocks of code to be executed
If Statement
Use the if statement to execute some code only if a specified condition is true.
if (condition)
{
code to be executed if condition is true
}
If...else Statement
Use the if....else statement to execute some code if a condition is true and another code if the
condition is not true.
if (condition)
{
code to be executed if condition is true
}
else
{
code to be executed if condition is not true
}
if (condition1) {
code to be executed if condition1 is true
}
else if (condition2) {
code to be executed if condition2 is true
}
else {
code to be executed if neither condition1 nor condition2 is true
}
switch(n)
{
case 1:
execute code block 1
break;
case 2:
execute code block 2
break;
default:
code to be executed if n is different from case 1 and 2
}
Conditional Operator
JavaScript also contains a conditional operator that assigns a value to a variable based on some
condition.
variablename=(condition)?value1:value2
voteable=(age<18)?"Too young":"Old enough";
while (condition)
{
code block to be executed
}
do
{
code block to be executed
}
while (condition);
JavaScript Objects
JavaScript has several built-in objects, like String, Date, Array, and more.
An object is just a special kind of data, with properties and methods.
objectName.propertyName
This example uses the length property of the String object to find the length of a string:
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script>
function person(firstname, lastname, age)
{
this.firstname = firstname;
this.lastname = lastname;
this. age = age;
}
var person1=new person("Narendra","Modi",24);
document.write(person1.firstname + + person1.lastname + + person1.age);
</script>
</body>
</html>
In above the function personbecomes the constructor invoked through the new keyword on
assignment to the person1 variable.
Here the values are passed as parameters to the constructor.
Inside the constructor the this keyword takes on the value of the newly created object and therefore
applies properties to it.
<form name=userDetails>
<input type=text name= fname/>
<input type=text name= lname/>
<input type=submit name= Submit/>
The form data can then be accessed with various DOM syntax constructions. The form itself can be
accessed through:
document.forms[0];
<script type="text/javascript">
functionincrementCurrent() {
current = parseInt(document.forms["noteForm"].total.value);
document.forms["noteForm"].total.value = current + 1;
}
</script>
</head><body>
<div id="mainDiv">
<h1>Document Object Example</h1>
<form id="noteForm">
Current number of notes:
<input type="text" name="total" value="0" size="3"/>
<input type="button" value="Add a new note"
onclick="incrementCurrent()"/>
</form>
</div>
</body></html>
The idea behind JavaScript form validation is to provide a method to check the user
enteredinformation before they can even submit it.
JavaScript also lets you display helpful alerts to inform the user what information they have entered
incorrectly and how they can fix it.
<html>
<head>
<title>JavaScript Forms</title>
</head>
<body>
<form method=post name=getinfo onSubmit=return processForm()>
<input type=text name=email/>
<input type=submit value=log in name=Login/>
</form>
^*\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w+$
The first section is:
^[\\w-_\.]
This sequence, beginning with ^, means check the first character is a word character represented by
\\w.
The next part is :
*[\\w-_\.]
The * means that the next series of characters described can be represented many times or not at
all.
The characters themselves are the same as before; that is word characters, underscore, hyphen or
period.
\@[\\w]\.+
The first set in square brackets makes sure that there are some characters after the dot and the last
part checks that the last character is a word character.
In this program after the string is declared, a regular expression object is created with the pattern:
var regex = new RegExp(emailpattern);
The pattern can then be tested against the incoming parameter with objects test method:
returnregex.test(chkMail);
This will return true or false depending on whether there is a match or not.
var x=Math.PI;
var y=Math.sqrt(16);
XML
What is XML?
XML is a meta-language, which can be used to store data & act as a mechanism to transfer
information between dissimilar systems.
XML stands for EXtensible Markup Language.
XML is a markup language much like HTML.
XML was designed to describe data.
XML tags are not predefined in XML. You must define your own tags.
XML is self describing.
XML uses a DTD (Document Type Definition) to formally describe the data.
<?xml version=1.0?>
<Person>
<Firstname>Ralph</Firstname>
<Lastname>Mosely</Lastname>
</Person>
Use of XML
Used to exchange data between dissimilar systems.
Used to describe content of document.
XML can be used as database to store data.
Features of XML
XML has its own tag so its self describing.
Language Independent:Any language is able to read & write XML.
OS Independent: can be work on any platform.
Readability: Its a plain text file in user readable format so you can edit or viewin simple editor.
<bookstore>
<book category="CHILDREN">
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
<file type="gif">computer.gif</file>
Xmlns=http://www.mydomian.com/ns/animals/1.1
<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Ravi</to>
<from>Ketan</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>
<to>Ravi</to>
<from>Narendra</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
o This is a copy of the file "note.dtd" containing the Document Type Definition:
<?xml version="1.0"?>
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
DTD - Elements
In the DTD, XML elements are declared with an element declaration. An element declaration has the
following syntax:
Empty elements
o Empty elements are declared with the keyword EMPTY inside the parentheses:
o #CDATA means the element contains character data that is not supposed to be parsed bya
parser.
o #PCDATA means that the element contains data that IS going to be parsed by a parser.
o The keyword ANY declares an element with any content.
o If a #PCDATA section contains elements, these elements must also be declared.
Elements with children (sequences)
o Elements with one or more children are defined with the name of the children
elementsinside the parentheses:
o When children are declared in a sequence separated by commas, the children must appearin
the same sequence in the document. In a full declaration, the children must also bedeclared,
and the children can also have children. The full declaration of the notedocument will be:
Wrapping
o If the DTD is to be included in your XML source file, it should be wrapped in aDOCTYPE
definition with the following syntax:
o The example declaration above declares that the child element message can only occurone
time inside the note element.
Declaring minimum one occurrence of the same element
o The * sign in the example above declares that the child element message can occur zeroor
more times inside the note element.
Declaring zero or one occurrences of the same element
o The? Sign in the example above declares that the child element message can occur zeroor
one times inside the note element.
DTD Attributes
Attributes provide extra information about elements.
Attributes are placed inside the start tag of an element.
Declaring Attributes
o In the DTD, XML element attributes are declared with an ATTLIST declaration. Anattribute
declaration has the following syntax:
o As you can see from the syntax above, the ATTLIST declaration defines the elementwhich
can have the attribute, the name of the attribute, the type of the attribute, and thedefault
attribute value.
o The attribute-type can have the following values:
DTD example:
<!ELEMENT square EMPTY>
<!ATTLIST square width CDATA "0">
XML example:
<square width="100"></square>
o In the above example the element square is defined to be an empty element with
theattributes width of type CDATA. The width attribute has a default value of 0.
XML Schema
An XML Schema describes the structure of an XML document.
XML Schema is an XML-based alternative to DTD.
The XML Schema language is also referred to as XML Schema Definition (XSD).
XML Schema is a W3C Recommendation.
XSD Elements
XML Schemas define the elements of your XML files. Its of two types:
o Simple
o Complex Type
<lastname>Refsnes</lastname>
<age>36</age>
<dateborn>1970-03-27</dateborn>
<product pid="1345"/>
o A complex XML element, "employee", which contains only other elements:
<employee>
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>
<description>
It happened on <date lang="norwegian">03.03.99</date> ....
</description>
XSD Attributes
Simple elements cannot have attributes. If an element has attributes, it is considered to be of a
complex type. But the attribute itself is always declared as a simple type.
How to Define an Attribute?
o The syntax for defining an attribute is:
XSL
What is XSL?
XSL stands for EXtensible Stylesheet Language.
XSL = Style Sheets for XML
XSL describes how the XML document should be displayed!
XSL More Than a Style Sheet Language
XSL consists of three parts:
o XSLTa language for transforming XML documents
o XPatha language for navigating in XML documents
o XSLFOa language for formatting XML documents
What is XSLT?
XSLT stands for XSL Transformations.
XSLT is the most important part of XSL.
XSLT transforms an XML document into another XML document.
XSLT uses XPath to navigate in XML documents.
Linking
The style sheet is linked into the XML by adding the connecting statement to the XML document:
<?xmlstylesheet type=text/xsl href=libstyle.xsl ?>
XSL Transformations
XSLT is the most important part of XSL.
XSLT is used to transform an XML document into another XML document, or another type of
document that is recognized by a browser, like HTML and XHTML. Normally XSLT does this by
transforming each XML element into an (X)HTML element.
With XSLT you can add/remove elements and attributes to or from the output file. You can also
XSL Elements
XSL contains many elements that can be used to manipulate, iterate and select XML, for output.
o valueof
o foreach
o sort
o if
o choose
<xsl:value-of> Element
The <xsl:valueof> element extracts the value of a selected node.
The <xsl:valueof> element can be used to select the value of an XML element and add it to the
output.
Syntax
<xsl:valueof select="expression" />
o expression: This is Required. An XPath expression that specifies which node/attribute to
extract the value from. It works like navigating a file system where a forward slash (/) selects
subdirectories.
<xsl:for-each> Element
The XSL <xsl:foreach> element can be used to select every XML element of a specified nodeset.
<xsl:if> Element
To put a conditional if test against the content of the XML file, add an <xsl:if> element to the XSL
document.
Syntax
<xsl:if test="expression">
...some output if the expression is
true...
</xsl:if>
<xsl:sort> Element
The <xsl:sort> element is used to sort the output.
<xsl:sort select="artist"/>
The select attribute indicates what XML element to sort on.
<xsl:choose> Element
The <xsl:choose> element is used in conjunction with <xsl:when> and <xsl:otherwise> to express
multiple conditional tests.
<xsl:apply-templates> Element
The <xsl:apply-templates> element applies a template to the current element or to the current
element's child nodes.
If we add a select attribute to the <xsl:apply-templates> element it will process only the child
element that matches the value of the attribute. We can use the select attribute to specify the order
in which the child nodes are processed.
Look at the following XSL style sheet:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="cd">
<p>
<xsl:apply-templates select="title"/>
<xsl:apply-templates select="artist"/>
</p>
</xsl:template>
</xsl:stylesheet>
Using JavaScript
One way to process and transform XML on the client side is using JavaScript, which has several
features for doing the task very well.
<html>
<body>
<script type=text/javascript>
//Load the XML document
var xml= new ActiveXObject(Microsoft.XMLDOM)
xml.async=false
xml.load(lib.xml)
//Load the XSL document
var xsl= new ActiveXObject(Microsoft.XMLDOM)
xsl.async= false
xsl.load(libstyle.xsl)
//Do the actual transform
document.write(xml.transformNode(xsl))
</script>
</body>
</html>
Above example shows one way to transform with JavaScript using Microsofts proprietary
Application Programming Interface (API) for the Internet Explorer browser.
It is also possible to process XML using the DOM.
Using both the of these mechanisms it is possible to also traverse an XML document and process
either according to a style sheet or simply using the JavaScript to make the stylistic decisions.
Apart from JavaScript, it is also possible to use other programming languages (such as Java and .Net)
to process and then output a transformed document.
PHP
PHP is a generalpurpose serverside scripting language originally designed for web development to
produce dynamic websites.
PHP scripts execute on web server and serve WebPages to user on request.
PHP was originally created by RasmusLerdorf in 1994. Programmer RasmusLerdorf initially created a
set of C scripts he called "Personal Home Page Tools" to maintain his personal homepage. The scripts
performed tasks such as displaying his rsum and recording his webpage traffic.
These were released and extended to include a package called the Form Interpreter (PHP/FI). While
PHP originally stood for "Personal Home Page", it is now said to stand for "PHP: Hypertext
Preprocessor", a recursive acronym.
PHP code is embedded into the HTML source document and interpreted by a web server with a PHP
processor module, which generates the web page document. It also has evolved to include a
commandline interface capability and can be used in standalone graphical applications.PHP can be
deployed on most web servers and as a standalone interpreter, on almost every operating system
and platform free of charge.
In 1997 ZeevSuraski and AndiGutmans along with Rasmus rewrite PHP and released PHP version 3.0
in June 1998.After this release PHP becomes so much popular.
The PHP version 4.0 was launched in May 2000.This version includes session handling, output
buffering, a richer cire language and support for wide variety of web server platforms.
The PHP 5.0 version released in 2004 with object oriented programming concept.
Web Server
A Web Server is computer and the program installed on it. Web Server interacts with the client
through the browser. It delivers the web pages to the client and to an application by using the web
browser and HTTP protocol respectively.
We can also define the web server as the package of larger number of programs installed on a
computer connected to internet or intranet for downloading the requested files using File Transfer
Protocol, serving e mail and building and publishing web pages.
Prof. Arjun Bala, CE Department | 2160708 Web Technology 1
7 PHP
A web server works on client server model. A computer connected to internet or intranet must have
a server program.
A computer connected to the internet for providing the services to a small company or a department
store may contain the HTTP server to access and store WebPages and files, SMTP server to support
mail services, FTP server for files downloading and NNTP server for newsgroup.
The computer containing all the above servers is called the web server.
MySQL
MySQL is a relational database management system (RDBMS) that runs as a server providing
multiuser access to a number of databases.
It is named after developer Michael Widenius' daughter, My. The SQL phrase stands for Structured
Query Language.
The data in MySQL is stored in database objects called tables. A table is a collection of related data
entries and it consists of columns and rows.
The MySQL development project has made its source code available under the terms of the License.
The license can require improved versions of the software to carry a different name or version from
the original software.
First released in January,1998, MySQL was owned and sponsored by the Swedish company MySQL
AB, now owned by Oracle Corporation.
MySQL is fully multithreaded using kernel threads, and provides application programming interfaces
(APIs) for many programming languages, including C,C++, Java, Perl, PHP, Python.
MySQL is used in a wide range of applications, including data warehousing, ecommerce, Web
databases, logging applications and distributed applications.
PHP
PHP is a server side scripting that was designed for creating dynamic websites. It slots into your
Apache web server and processes instructions contained in a web page before that page is sent
through to your web browser.
PHP is a powerful scripting language that can be run in the command line of any computer with
PHPinstalled. However, PHP alone isn't enough in order to build dynamic web sites.
Apache
To use PHP on a web site, you need a server that can process PHP scripts. Apache is a free web
Server that, once installed on a computer, allows developers to test PHP scripts locally; this makes it
an invaluable piece of your local development environment.
Like all web servers, Apache accepts an HTTP request and serves an HTTP response.
MySQL
Additionally, dynamic websites are dependent on stored information that can be modified quickly
and easily; this is the main difference between a dynamic site and a static HTML site. However, PHP
doesnt provide a simple, efficient way to store data. This is where a relational database
management system like MySQL comes into play. PHP provides native support for it and the
database is free, opensource project.
MySQL is a relational database management system (DBMS). Essentially, this means that MySQL
allows users to store information in a tablebased structure, using rows and columns to organize
different pieces of data.
Numeric Array
Associative Array
Multidimensional Array
Numeric Array
In numeric array each element having numeric key associated with it that is starting from 0;
You can use array() function to create array.
The general syntax is given below:
$array_name=array ( value1, value2 valueN);
For Example:
<?php
$myarray=array(A,B,C);
print_r($myarray);
?>
Output:
Array( [0]=>A [1]=>B [2]=>C)
You can refer to individual element of an array in PHP script using its key value as shown below:
<?php
$myarray=array(A,B,C);
echo $myarray[1];
?>
It will display
B
In Numeric Array you can use for, while or do while loop to iterate through each element in array
because in numeric array key values are consecutive.
<?php
$myarray=array(Apache, MySQL, PHP);
for($i=0;$i<3;$i++)
{
echo $myarray*$i+.<br>;
}
?>
Output:
Apache
MySQL
PHP
Associative Array
The associative part means that arrays store element values in association with key values rather
than in a strict linear index order.
If you store an element in an array, in association with a key, all you need to retrieve it later from
that array is the key value.
Key may be either numeric or string.
You can use array() function to create associative array.
The general syntax is given below:
$array_name=array(key1=>value1, key1=>value1,.. keyN=>valueN);
For Example 1:
<?php
$myarray=array(5=>Apple, 10=>Mango, 20=>Grapes);
print_r($my_array);
?>
Output:
Array([5]=>Apple [10]=>Mango [20]=>Grapes)
Example 2:
<?php
$myarray=array(Name=>James , Age=>25, Gender=>Male );
print_r($myarray);
?>
Output:
Array([Name]=>James [Age]=>25 [Gender]=>Male)
You can refer to individual element of an array in PHP using its key value.
Example:
<?php
$myarray=array(Name=>James , Age=>25, Gender=>Male );
echo Name:.$myarray*Name+;
?>
Output:
Name:James
In associative array you cannot use for, while r do..while loop to iterate through each element in
array because in Associative array key value are not consecutive.
So you have to use foreach loop.
For Example:
<?php
$myarray=array(Name=>James , Age=>25, Gender=>Male );
foreach($myarray as $item)
{
echo $item;
}
?>
Output:
James 25 Male
Multidimensional Array
PHP can easily support multidimensional arrays, with arbitrary numbers of key.And just as in one
dimensional arrays, there is no need to declare out intentions in advance. Assignment can be like:
The values those are stored in array can themselves be arrays, just as legitimately as they can be string or
numbers.
For example:
The integer key of 0 stores a string, and the key 1 stores an array that ,in turn, has a string in it.
It is simply an array with two values stored in association with keys.Each of them values is an array itself. We
can reference it like this
echo $basket*fruit+*black+;
$kind=flower;
$color=yellow;
print( $basket *$kind+ *$color+);
How do you create session & cookie in PHP? Give difference between
session and cookie with example. OR
What are cookies? Explain the cookies handling in PHP with proper
example.
PHP Sessions
A PHP session variable is used to store information about, or change settings for a user session.
Session variables hold information about one single user, and are available to all pages in one
application.
<?phpsession_start(); ?>
<html>
<body>
</body>
</html>
The code above will register the user's session with the server, allow you to start saving user
information, and assign a UID for that user's session.
<?php
session_start();
// store session data
$_SESSION['views']=1;
?>
<html>
<body>
<?php
//retrieve session data
echo "Pageviews=". $_SESSION['views'];
?>
</body>
</html>
Output:Pageviews=1
In the example below, we create a simple page-views counter. The isset() function checks if the
"views" variable has already been set. If "views" has been set, we can increment our counter. If
"views" doesn't exist, we create a "views" variable, and set it to 1:
<?php
session_start();
if(isset($_SESSION['views']))
$_SESSION['views']=$_SESSION['views']+1;
else
$_SESSION['views']=1;
echo "Views=". $_SESSION['views'];
?>
Destroying a Session
If you wish to delete some session data, you can use the unset() or the session_destroy() function.
The unset() function is used to free the specified session variable:
<?php
unset($_SESSION['views']);
?>
You can also completely destroy the session by calling the session_destroy() function:
<?php
session_destroy();
?>
Note:session_destroy() will reset your session and you will lose all your stored session data.
PHP Cookie
A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's
computer.
Each time the same computer requests a page with a browser, it will send the cookie too. With PHP,
you can both create and retrieve cookie values.
In the example below, we will create a cookie named "user" and assign the value "Alex Porter" to it.
We also specify that the cookie should expire after one hour:
<?php
setcookie("user", "Alex Porter", time()+3600);
?>
<html>
.....
Note: The value of the cookie is automatically URLencoded when sending the cookie, and
automatically decoded when received (to prevent URLencoding, use setrawcookie() instead).
You can also set the expiration time of the cookie in another way. It may be easier than using
seconds.
<?php
$expire=time()+60*60*24*30;
setcookie("user", "Alex Porter", $expire);
?>
<html>
.....
In the example above the expiration time is set to a month (60 sec * 60 min * 24 hours * 30 days).
<?php
// Print a cookie
echo $_COOKIE["user"];
In the following example we use the isset() function to find out if a cookie has been set:
<html>
<body>
<?php
if (isset($_COOKIE["user"]))
echo "Welcome " . $_COOKIE["user"] . "!<br />";
else
echo "Welcome guest!<br />";
?>
</body>
</html>
<html>
<body>
<form action="welcome.php" method="post"> Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>
<html>
<body>
Welcome <?php echo $_POST["name"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old.
</body>
</html>
How can you connect to database in PHP? Show the simple database
operation using PHP with proper example.
Integration of PHP with MySQL
It is possible to execute various commands of MySQL from PHP.PHP provides various built-in
functions which you allows you to use MySQL commands from PHP page. Thus you can integrate
PHP with MySQL.
Following are the various PHP functions that allows you the facility of integrating PHP with MySQL:
mysql_connect()
Before you can access data in a database, you must create a connection to the database.
This function allows you to establish connection of PHP application with MySQL server.
Syntax: mysql_connect(servername,username,password);
servername Indicates the name of MySQL server with which you want to establish
connection.
It is optional .Default value is localhost:3306
UserName Indicates the name of user using which you can logs on to MySQL Server.
Optional. Default value is the name of the user that owns the server process.
Password Indicates password of the user using which you can logs on to MySQL Server.
It is optional. Default is "".
If connection establish successfully with MySQL Server then this function returns TRUE value
otherwise it returns FALSE.
Example
<?php
$conn=mysql_connect(localhost,root,);
if($conn)
{
echo Connected with MySQL;
}
else
{
echo Could not connect to database;
}
?>
mysql_select_db()
This function allows you to select database from the list of MySQL server databases.
Syntax: mysql_select_db (DatabaseName, ConnectionName);
DatabaseName Indicates the name of the database that you want to select.
ConnectionName Indicates the name of the variable that is used at the time of establish
connection with MySQL server using mysql_connect() function.
<?php
$conn=mysql_connect(localhost,root,);
$db=mysql_select_db(Mydatabse);
if($db)
{
echo Database Selected Successfully ;
}
else
{
echo Error in selecting Database.;
}
?>
mysql_query()
This function allows you to specify and execute the MySQL command on MySQL Server.
Syntax:
mysql_query(Query, ConnectionName);
<?php
$conn=mysql_connect(localhost,root,);
$db=mysql_select_db(Mydatabse, $conn);
$cmd=mysql_query(create table Test(ID integer, Name varchar(20)));
if($cmd)
{
echo Table created Successfully ;
}
else
{
echo Error in executing query.;
}
?>
mysql_fetch_row()
This function allows you to retrieve a record from the recordset that is returned from executing
the MySQL query.
Prof. Arjun Bala, CE Department | 2160708 Web Technology 2
8 PHP and MySQL
The record that is returned by this function is in the form of numeric array. Numeric array contains
index and value associated with that index.
If there is no record in the record set then it returns false value.
Syntax:
mysql_fetch_row(VariableName);
VariableName indicates the record set that is returned from executing the MySQL command using
mysql_query() function.
Example:
<?php
$conn=mysql_connect(localhost,root,);
$db=mysql_select_db(Mydatabse, $conn);
$query=select * from product_master;
$result=mysql_query($query,$conn);
$ans=mysql_fetch_row($result);
print_r($ans);
mysql_close($con);
?>
mysql_fetch_array()
This function allows you to retrieve a record from the recordset that is returned from executing
the MySQL query.
The record that is returned by this function is in the form of either numeric array, associative array
or both.
If there is no record in record set then it will returns false value.
Syntax:
mysql_fetch_array(VariableName, ResultArrayType)
VariableName:- indicates the record set that is returned from executing the MySQL command
using mysql_query() function.
ResultArrayType:-indicates the type of array to be returned. It can have one of the following
values:
MYSQL_ASSOC This type of array contains name of the field and the value associated with that
field for current record.
MYSQL_NUM This type of array contains index of the field and the value associcated with that
index for current record.
MYSQL_BOTH It is combination of both Associative array and Numeric array. It is the default
type to be returned by this function.
mysql_fetch_assoc()
This function allows you to retrieve a record from the recordset that is returned from executing
the MySQL query in the form of associative array.
Syntax:
mysql_fetch_assoc(VariableName)
Returns an associative array that corresponds to the fetched row, or FALSE if there are no more
rows.
Example:
<?php
$conn=mysql_connect(localhost,root,);
$db=mysql_select_db(Mydatabse, $conn);
$query=select * from product_master;
$result=mysql_query($query, $conn);
$ans=mysql_fetch_assoc($result);
print_r($ans);
mysql_close($con);
?>
<?php
$conn=mysql_connect(localhost,root,);
$db=mysql_select_db(Mydatabse, $conn);
$query=select * from product_master;
$result=mysql_query($query, $conn);
while($ans=mysql_fetch_assoc($result))
{
echo $ans*field1+.<br>;
echo $ans*field2+.<br>;
}
mysql_close($con);
?>
mysql_num_rows()
This function allows you to retrieve number of records available in the record set.
Syntax:
mysql_num_rows(ResultVariable);
ResultVariable is the variable that holds result returned by mysql_query() function.
Example:
<?php
$conn=mysql_connect(localhost,root,);
$db=mysql_select_db(Mydatabse, $conn);
$query=select * from product_master;
$result=mysql_query($query, $conn);
$total_records=mysql_fetch_rows($result);
echo Total Records:.$total_records;
mysql_close($con);
?>
mysql_error()
This function allows you to retrieve theerror text from the most recently executed MySQL
function.
If no error encountered while executing the script then it will returns blank string.
If the mysql operation contains more than one error then it will returns error description of the
last statement in which error is encountered.
Syntax:
mysql_error();
mysql_close()
This function allows you to close the connection that is established using mysql_connect()
function.
Syntax:mysql_close(ConnectionName);
ConnectionName :- Indicates the name of the variable that is used at the time of establish
connection with MySQL server using mysql_connect() function.
It returns true is connection is closed successfully otherwise it returns false.
Example:
<?php
$conn=mysql_connect(localhost,root,);
mysql_close($con);
?>