HTML 2
HTML 2
BEGINNERS
[Document subtitle]
About this Book
Audience
These questions have been designed to meet the requirements of all
those readers who are keen to prepare for the web development
interview.
Prerequisites
This book assumes you have some knowledge on Web Programming
and assume you know how to work with HTML, CSS, JavaScript, PHP,
MySQL and WordPress. This book will not teach you how to work
with Web Programming.
All the content and graphics published in this e-book are the
property of PHPBootcamp.com. The user of this e-book is prohibited
to reuse, retain, copy, distribute or republish any contents or a part
of contents of this e-book in any manner without written consent of
the publisher.
Support
You can reach me for technical discussions and other support
related queries from here.
Free Courses
Learn JAVASCRIPT in 1
Hour
Table of Contents
1. HTML
1. HTML
1) What is HTML?
No. There are some HTML tags that don't need a closing tag. For
example: <image> tag, <br> tag.
The HTML formatting is a process of format the text for a better look
and feel. It uses different tags to make text bold, italicized,
underlined..
5) What are some of the common lists that can be used when
designing a page?
No, there are some character entities that cannot be displayed when
the operating system that the browser is running on does not
support the characters. When that happens, these characters are
displayed as boxes.
Image map lets you link to many different web pages using a single
image. You can define shapes in images that you want to make part
of an image mapping.
To insert the copyright symbol, you need to type © or & #169; in
an HTML file.
11) How do you create links to sections within the same page?
Links can be created using the <a> tag, with referencing through the
use of the number (#) symbol. For example, you can have one line as
<a href=”#topmost”>BACK TO TOP</a>, which would result in the
words “BACK TO TOP” appearing on the webpage and links to a
bookmark named topmost. You then create a separate tag command
By using indents, you can keep the list elements straight. If you
indent each subnested list in further than the parent list that
contains it, you can at a glance determine the various lists and the
elements that it contains.
Every web page on the web can have a separate web address. Most
of these addresses are relative to the top-most web page. The
published web address that appears within magazines typically
points this top-most page. From this top level page, you can access
all other pages within the website.
When you use image maps, it can easily become confusing and
difficult to determine which hotspots correspond to which links.
Using alternative text lets, you put a descriptive text on each hotspot
link.
Yes, older HTML files are compliant to the HTML standard. Most
older files work on the newer browsers, though some features may
not work.
No, hyperlinks can be used in the text as well as images. That means
you can convert an image into a link that will allow users to link to
another page when clicked. Surround the image within the <a href=”
“>…</a> tag combinations.
17) If the user’s operating system does not support the needed
character, how can the symbol be represented?
18) How do you change the number type in the middle of a list?
The <li> tag includes two attributes – type and value. The type
attribute can be used to change the numbering type for any list item.
The value attribute can change the number index.
With ordered lists, you can select to use some different list types
including alphabetical and Roman numerals. The type attribute for
unordered lists can be set to disc, square, or circle.
22) Why are there both numerical and named character entity
values?
The numerical values are taken from the ASCII values for the various
characters, but these can be difficult to remember. Because of this,
named character entity values were created to make it easier for web
page designers to use.
If two sets of HTML tags are overlapped, only the first tag will be
recognized. You will find this problem when the text does not display
properly on the browser screen.
Applets are small programs that can be embedded within web pages
to perform some specific functionality, such as computations,
animations, and information processing. Applets are written using
the Java language.
without a closing tag like the <img> tag, do not require any text
between them.
You can specify a border color using style sheets, but the colors for a
table that does not use style sheets will be the same as the text
color.
29) How do you create a link that will connect to another web
page when clicked?
30) What other ways can be used to align images and wrap text?
Tables can be used to position text and images. Another useful way
to wrap text around an image is to use style sheets.
31) Can a single text link point to two different web pages?
No. The <a> tag can accept only a single href attribute, and it can
point to only a single web page.
32) What is the difference between the directory and menu lists
and the unordered list?
The key difference is that the directory and menu lists do not include
attributes for changing the bullet style.
The bullet color is always the same as that of the first character in
the list item. If you surround the <li> and the first character with a set
of <font> tags with the color attribute set, the bullet color, and the
first character will be a different color from the text.
Any <tr> tag can be changed to a <th> tag. This causes the text
contained within the <th> tag to be displayed as bold in the browser.
Although <th> tags are mainly used for headings, they do not need
to be used exclusively for headings.
38) How do you create text on a webpage that will allow you to
send an email when clicked?
To change text into a clickable link to send email, use the mailto
command within the href tag. The format is as follows:
39) Are <br> tags the only way to separate sections of text?
No. The <br> tag is only one way to separate lines of text. Other
tags, like the <p> tag and <blockquote> tag, also separate sections of
text.
40) Are there instances where the text will appear outside of the
browser?
The default color for normal and active links is blue. Some browsers
recognize an active link when the mouse cursor is placed over that
link; others recognize active links when the link has the focus. Those
that don’t have a mouse cursor over that link is considered a normal
link.
Style sheets do not limit the number of style definitions that can be
included within the brackets for a given selector. Every new style
definition, however, must be separated from the others by a
semicolon symbol.
43) Can I specify fractional weight values such as 670 or 973 for
font weight?
You can define several selectors with the same style definition by
separating them with commas. This same technique also works for
selectors with class names.
46) What happens if you open the external CSS file in a browser?
When you try to open the external CSS file in a browser, the browser
cannot open the file, because the file has a different extension. The
only way to use an external CSS file is to reference it using <link/> tag
within another HTML document.
Frames can make navigating a site much easier. If the main links to
the site are located in a frame that appears at the top or along the
edge of the browser, the content for those links can be displayed in
the remainder of the browser window.
The browser sizes the frames relative to the total sum of the values.
If the cols attribute is set to 100%, 200% the browser displays two
vertical frames with the second being twice as big as the first.
<Video> and <Audio> are new tags which are included in HTML5
version. They are mainly used as a replacement for Flash, Silverlight,
and similar technologies to play multimedia items.
53) Do you know which are two semantic tags are included in
HTML5 version?
The <article> and <section> tags are two new tags that are included
in HTML5. Articles can be composed of multiple sections that can
have multiple articles. An article tag represents a full block of content
which is a section of a bigger whole.
56) What are the new FORM elements which are available in
HTML5?
Session Storage:
It stores data of current session only. It means that the data stored in
session storage clear automatically when the browser is closed.
Local Storage:
Offline browsing – Web users can also use the application when they
are offline.
Reduce the server load – The web browser will only download
updated resources from the server.
60) Explain five new input types provided by HTML5 for forms?
datetime-local: This input type allows the user to select a date and
time without time zone.
datetime: This input type allows the user to select a date and time
with time zone.
SVG is resolution independent as it’s not losing its quality when they
are resized or zoomed
A static webpage is an html web page and dynamic web pages are
XHTML.
<html>
<head>
<style>
h1{
color: red;
h2{
color: blue;
h3{
color : green;
h4{
color: purple;
h5{
color: yellow;
h6{
color: orange;
</style>
</head>
<body>
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
</body>
</html>
Output:
Ordered List (<ol>) – An Ordered List or ol tag are the list which will
list the items in an ordered way, i.e. numbered or alphabetically.
Meta tags in html are used by the developer to tell the browser
about the page description, author of the template, character set,
keywords and many more.
Meta tags are used for search engine optimization to tell the search
engine about the page contents.
<meta charset="UTF-8">
<br> tags are used to enter a new line into the HTML contents. These
tags are generally used to separate two different lines of text
between each other.
document.getElementById(“inputField”).attr(“type”, “password”);
HTML pages are saved by adding .html or .html in web page name.
<head>
<title></title>
</head>
<body>
</body></html>
77) Name some new features which were not present in HTML
but are added to HTML5?
main – The main tag defines the main section in the document which
contains the main content of the document. <main></main>
figcaption – Figcaption tag defines the caption for the media element
such as an image or video. <figcaption></figcaption>
77) What is Anchor tag and how can you open an URL into a new
tab when clicked?
Anchor tag in HTML is used for linking between two sections or two
different web pages or website templates.
To open an url into a new tab in the browser upon a click, we need to
add target attribute equal to _blank.
<a href=”#” target=”_blank”></a>
78) Write an HTML code to form a table to show the below values in
a tabular form with heading as Roll No., Student name, Subject
Name, and values as
1, Ram, Physics
2, Shyam, Math
3, Murli, Chemistry
To represent the above values in an HTML table format, the code will
be:
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
</style>
</head>
<body>
<table >
<tr>
</tr>
<tr>
<td> 1 </td>
<td>Ram</td>
</tr>
<tr>
<td> 2 </td>
</tr>
<tr>
<td> 3 </td>
</tr>
</table>
</body>
</html>
Output:
Block elements are the blocks that take the full available width and
always start from a new line. It will stretch itself to the full available
width of the available container width. Block level elements are
<div>, <p>, <img>, <section> and many more.
Inline elements are the elements that will only take the width that is
required to fit into the container.
For Example, take the flow of text on the page. When the line of the
text takes the full width of the container it wraps itself into a new line
and again goes in the same way.
Whereas the inline element will take only that much space or width
that it is needed for them. Inline elements are <span>, <label>, <a>,
<b> and many more.
Tags
Most tags have opening and closing tags. The opening tag is written
with the tag name in angled brackets, like <tagname> whereas the
closing tag adds a forward slash: </tagname>. Anything between
these opening and closing tags is considered to be contents of that
tag.
Some tags, like the <img> tag are self-closing. This means that they
cannot have any content. For example, an image can’t contain
additional HTML elements within it. The only way to change their
behavior or appearance is through attributes or CSS.
<img src="http://placekitten.com/200/300" />
Each tag can also have additional attributes, which change the way
the tag behaves or is displayed. For example, an <input> tag has
a type attribute, which you can use to specify whether it’s a text field,
checkbox, radio button or one of many more options.
Attributes are specified directly after the name of the tag, inside the
two angled brackets. They should only ever appear in opening tags
or in self-closing tags - they can never be in closing tags. They are
followed by an equals sign = and the chosen value in double
quotes ". Take care not to include any spaces before and after the
equals sign! Multiple attributes can be defined on a single tag,
separated by a space.
<!-- Text field -->
There are some attributes that are available on every single tag - like
the style attribute - however, most tags also have their own specific
ones as those attributes simply wouldn’t make sense on tags of a
different type (like an image source attribute on a paragraph tag).
span multiple
<!-- All of this is ignored. Even valid HTML like this: <span>Ska—
doosh!</span> -->
Block
Inline
were to tack more text onto an existing line of text, it will stay on the
same line, as if it was all part of the same text to begin with.
Text
Tag Description
strong,
Renders a piece of text bold.
b
Tag Description
Layout
Tag Description
Stands for ordered list. Each item inside this list will have an
incremented number or symbol beside them (e.g. 1, 2, 3 or
ol
a, b, c). The symbols can be numbers, letters or roman
numerals.
Tag Description
your page’s layout, or you might get a phone call from the
90s.
Visual
Tag Description
Tag Description
src attribute inside the video tag to specify which file to load,
including backup options with different file types.
Just make sure your video is small in file size or you might get
some angry emails. You can specify whether you want it to
show video controls (like a play/pause button) and whether it
autoplays. Older browsers do not support this.
Forms
Tag Description
These are larger than simple text fields and allow the user
textarea
to enter line breaks as well. The size can be adjusted.
Tag Description
While each page is different, there are a few rules around the overall
structure of the HTML document. Let's look at the structure below:
DOCTYPE tag
HTML tag
</html>
Head tag
The first element inside the <html> tag is the <head> tag. Content
inside this tag is only meant for the browser and is not visible on the
page directly. Among other things, it contains the title of your page
(as shown in your browser tab), the character set used to display
content and more metadata (meaning data about data). This is also
where you define CSS and load some JavaScript (more about that
later).
<head>
<meta charset="UTF—8">
</head>
Body tag
After the <head> tag, still inside the <html> tag, we have
the <body> tag. It contains all the content that’s displayed in the
browser.
<body>
<h1>Welcome to my website!</h1>
</body>
With all of the above rules combined, we get something like this:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<h1>Welcome to my website!</h1>
</body>
</html>
The DOCTYPE for HTML5 is simple. Once you’ve added this to your
page, the browser will interpret everything else as HTML5.
<!DOCTYPE html>
When you’ve got a good grasp of HTML, your interviewer may ask
you some questions on how HTML works with CSS and JavaScript, to
tie everything together. If you are planning on working as a front end
developer, employers prefer some proficiency in all three languages.
Inline styles
You can add a style attribute to almost any tag. Inside this attribute
you can write your CSS rules.
<div style="background-color: red;">A container with a red
background.</div>
A style block
You are able to define one or more style blocks inside the head
section of your HTML document. Inside these blocks you can write
your CSS rules. You will have to specify which elements on the page
you’d like to style. In the below example, we’re targeting
the <body> tag and an element with a class attribute equal to .button.
<head>
<style>
body {
font-size: 16px;
.button {
padding: 10px;
</style>
</head>
By far the most recommended option is to link to a CSS file. This way
you are able to keep the content (HTML) separate from the way you
present that content (CSS). It also means you can use the same styles
on multiple pages. To link to a CSS file, you will have to add
a <link> tag to the <head> section in your document with
an href attribute that specifies the location of the CSS file.
<head>
</head>
Inline
A script block
You can define a script block anywhere on the page, which will get
executed as soon as the browser reaches that part of the document.
Note that this can be inside the <head> or <body> section of your
document.
<script>
var x = 5;
var y = 6;
var result = x + y;
</script>
file from the <head> or <body>, but keep in mind it will be loaded in
the order you’ve structured your document.
<script src="my-code.js"></script>
2. CSS
2. CSS
1) What is CSS?
• CSS1
• CSS2
• CSS2.1
• CSS3
• CSS4
• Bandwidth
• Site-wide consistency
• Page reformatting
• Accessibility
• Content separated from presentation
CSS frameworks are the preplanned libraries which make easy and
more standard compliant web page styling. The frequently used CSS
frameworks are: -
• Bootstrap
• Foundation
• Semantic UI
• Gumby
• Ulkit
1. <style>
2. body {
3. background-color: linen;
4. }
5. h1 {
6. color: red;
7. margin-left: 80px;
8. }
9. </style>
• You can create classes for use on multiple tag types in the
document.
• You can use selector and grouping methods to apply styles in
complex situations.
• No extra download is required to import the information.
• Selector
• Property
• Value
1. <style>
2. img.trans {
3. opacity: 0.4;
The universal selector matches the name of any of the element type
instead of selecting elements of a specific type.
1. <style>
2. *{
3. color: green;
4. font-size: 20px;
5. }
6. </style>
1. <style>
2. h2,p{
3. background-color: #b0d4de;
4. }
5. </style>
17) Which command is used for the selection of all the elements
of a paragraph?
1. <style>
2. body {
3. background-image: url("paper1.gif");
4. margin-left:100px;
5. }
6. </style>
19) Name the property for controlling the image position in the
background?
1. center
2. top
3. bottom
4. left
5. right
20) Name the property for controlling the image scroll in the
background?
1. <style>
2. .center {
3. text-align: center;
4. color: blue;
5. }
6. </style>
CSS Id Selector
1. <style>
2. #para1 {
3. text-align: center;
4. color: blue;
5. }
6. </style>
Inline: Inline Style Sheet is used to style only a small piece of code.
Syntax
Syntax
1. <style>
2. body {
3. background-color: linen;
4. }
5. h1 {
6. color: red;
7. margin-left: 80px;
8. }
9. </style>
10.
External: This is used to apply the style to all the pages within your
website by changing just one style sheet.
Syntax
1. <head>
2. <link rel="stylesheet" type="text/css" href="mystyle.css">
3. </head>
If a web page has a large number of images that take a longer time
to load because each image separately sends out an HTTP request.
The concept of CSS sprites is used to reduce the loading time for a
web page because it combines the various small images into one
image. It reduces the number of HTTP requests and hence the
loading time.
28) What is the CSS Box model and what are its elements?
The CSS box model is used to define the design and layout of
elements of CSS.
The CSS float property is used to move the image to the right or left
along with the texts to be wrapped around it. It doesn't change the
property of the elements used before it.
To understand its purpose and origin, let's take a look at its print
display. In the print display, an image is set into the page such that
text wraps around it as needed.
The closest option is to use the 'initial' property value, which restores
the default CSS values, rather than the browser's default styles.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. h1.vis {
6. visibility: visible;
7. }
8.
9. h1.hid {
10. visibility: hidden;
11. }
12. </style>
13. </head>
14. <body>
15. <h1 class="vis">It is visible</h1>
16. <h1 class="hid">It is hidden</h1>
17.
18. <p>Note - Second heading is hidden, but it still occupy spa
ce.</p>
19. </body>
20. </html>
21.
display: none also hides the element but not occupy space. It will
not affect the layout of the document.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. h1.vis {
6. display: block;
7. }
8.
9. h1.hid {
10. display: none;
11. }
12. </style>
13. </head>
14. <body>
15. <h1 class="vis">It is visible</h1>
16. <h1 class="hid">It is hidden</h1>
17.
18. <p>Note - Second heading is hidden and not occupy spac
e.</p>
19. </body>
20. </html>
It gives the impression that the first image has smoothly evolved into
the second one.
The main difference between CSS2 and CSS3 is that CSS3 is divided
into different sections which are also known as modules. Unlike
CSS2, CSS3 modules are supported by many browsers.
34) How can CSS be cascaded to mix with user’s personal sheet?
Rule, which is applicable in the entire sheet and not partly, is known
as at-rule. It is preceded by @ followed by A-Z, a-z or 0-9
Alternate Style Sheets allows the user to select the style in which the
page is displayed using the view>page style menu. Through Alternate
Style Sheet, user can see a multiple version of the page on their
needs and preferences.
By float property, the image can be moved to the right or the left
along with the text to be wrapped around it. Elements before this
property is applied do not change their properties.
• Height
• Max-height
• Max-width
• Min-height
• Min-width
• Width
CSS coding:
1 h1 {
2
3 color: blue;
4
5 }
6
7 h2 {
8
9 color: blue;
10
11 }
12
13 p {
14
15 color: blue;
16
17 }
It can be seen from the code that every element shares the same
property. Rewriting can be avoided by writing each selector
separated by a comma.
1 P
2
3 {
4
5 color: red;
6
7 text-align: left;
8
9 }
10
11 .marked
12
13 {
14
15 background-color: blue;
16
17 }
18
19 .marked p
20
21 {
22
23 color: green;
24
25 }
55) What is CSS Box Model and what are its elements?
This box defines design and layout of elements of CSS. The elements
are:
They are:
In CSS, you cannot revert back to old values due to lack of default
values. The property can be re- declared to get the default property.
58) What happens if 100% width is used along with floats all
across the page?
E.g.:
1B{
2
3 text-decoration: none;
4
5}
6
7 <B href="career.html" style="text-decoration: none">link text</B>
Classname
it can be A-Z, a-z or digits.
.top {font: 14em ;}, class selector
<Body class= “top”> this class is associated with element </body>
• Font-style
• Font-variant
• Font-weight
• Font-size/line-height
• Font-family
• Caption
• Icon
Benefits:
1 BODY {
2
3 width: 40em;
4
5 background: fluorescent;
6
7 }
8
9 P{
10
11 width: 30em;
12
13 margin-right: auto;
14
15 margin-left: auto
16
17 }
In this case, the left and right margins will be each, five ems wide
since they split up the ten ems left over from (40em-30em). It was
unnecessary for setting up an explicit width for the BODY element; it
was done here for simplicity.
Advantages are:
• Bandwidth
• Site-wide consistency
• Page reformatting
• Accessibility
• Content separated from presentation
Limitations are:
Both id and class is been used in HTML and assigns the value from
CSS.
It is used in CSS to define the hierarchy from the top level to the
bottom level. Inherited properties can be overridden by the children
class if the child uses the same name.
Example:
All the paragraph text will be displayed using the property and will be
defined in the body except for the H1 style which will show the text
in font 18 only.
Inline element does not have an element to set width and height and
also it does not have the line break.
#1) Sort by origin: There are some rules which can provide the
alternate way which can be defined as:
#3) Sort by order specified: This comes in the scenario when the
two selectors are same in weight and the other properties than the
specification which will be seen for overriding.
Example:
All other styles will be seen overridden if the style attribute is used
for inline style.
And also if the link element is used for external style, then it will
override the imported style.
For Example:
left:10px then the padding will shift to 10px in the left while absolute
is totally relative to the non-static parent.
It means if we write left:10px then the result will be 10px far from the
left edge of the parent element.
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
• Static(default)
• Relative
• Fixed
• absolute
By this property, we can transparent the image that can take the
values from 0.0-1.0, if the value is lower then the image is more
transparent. IE8 and earlier version of the browser can take the
values from 0-100.
img {
opacity: 0.6;
filter: alpha(opacity=60); /* For IE8 and earlier */}
For Example, we can style the first letter or line of an HTML element.
selector::pseudo-element {
property:value;
}
selector:pseudo-class {
property:value;
}
We can add icons to the HTML webpage by using an icon library like
font-awesome.
We have to add the name of the given icon class to any inline HTML
element. (<i> or <span>) . Icons in the icon libraries are scalable
vectors that can be customized with CSS.
In CSS, the box model is a box that binds all the HTML elements and
it includes features like margins, border, padding, and the actual
content.
By using box model we will get the authority to add the borders all
around the elements and we can also define the space between the
elements.
• margin-top
• margin-right
• margin-bottom
• Margin-left
1. Padding-top
2. Padding-right
3. Padding-bottom
4. Padding-left
div {
padding-top: 60px;
padding-right: 40px;
padding-bottom: 50px;
padding-left: 70px;
}
There are several properties of flexbox that are used in the HTML
webpage.
They are:
• flex-direction
• flex-wrap
• flex-flow
• justify-content
• align-items
• align-content
Example:
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: flex;
background-color: #f4b042;
</style>
</head>
<body>
<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
<p> Example of <em>flex</em>box.</p>
</body>
</html>
There are two types of gradients that are present in CSS. They are:
• Linear gradient
• Radial Gradient
Example:
#borderimg {
border: 15px solid transparent;
padding: 20px;
border-image: url(border.png) 30 round;
}
3. JAVASCRIPT
3. JAVASCRIPT
1) What is JavaScript?
o Lightweight
o Interpreted programming language
o Good for the applications which are network-centric
o Complementary to Java
o Complementary to HTML
o Open source
o Cross-platform
1. function msg()
2. {
3. document.writeln("Named Function");
4. }
5. msg();
1. function display()
2. {
3. document.writeln("Named Function");
4. }
5. display();
•
o Anonymous - These type of functions doesn't contain any
name. They are declared dynamically at runtime.
1. var display=function()
2. {
3. document.writeln("Anonymous Function");
4. }
5. display();
1. var display=function()
2. {
3. alert("Anonymous Function is invoked");
4. }
5. display();
The JavaScript string charAt() method is used to find out a char value
present at the specified index. The index number starts from 0 and
goes to n-1, where n is the length of the string. The index value can't
be a negative, greater than or equal to the length of the string. For
example:
1. var str="phpbootcamp";
2. document.writeln(str.charAt(4));
1. <script type="text/javascript">
2. document.write("JavaScript Hello World!");
3. </script>
2. function display()
3. {
4. document.writeln(msg); // It will not display the result.
5. }
6. display();
BOM stands for Browser Object Model. It provides interaction with the
browser. The default object of a browser is a window. So, you can call
all the functions of the window by specifying the window or directly.
The window object provides various properties like document,
history, screen, navigator, location, innerHeight, innerWidth,
The window object is used to display the popup dialog box. Let's see
with description.
Method Description
displays the alert box containing the message with ok
alert()
button.
function function_name(){
//function body
1.
1. Primitive Data Types - The primitive data types are as
follows:
1.
1. Non-primitive Data Types - The non-primitive data types
are as follows:
Data
Description
Type
represents an instance through which we can access
Object
members
Array represents a group of similar values
RegExp represents regular expression
1. document.getElementById('mylocation').innerHTML="<h2>This
is heading using JavaScript</h2>";
1. document.getElementById('mylocation').innerText="This is text
using JavaScript";
1. By array literal
2. By creating an instance of Array
3. By using an Array constructor
1. var emp=["Shyam","Vimal","Ratan"];
1. function number(num) {
2. if (isNaN(num)) {
3. return "Not a Number";
4. }
5. return "Number";
6. }
7. console.log(number('1000F'));
8. // expected output: "Not a Number"
9.
10. console.log(number('1000'));
11. // expected output: "Number"
3030 because 10+20 will be 30. If there is numeric value before and
after +, it treats as binary + (arithmetic operator).
1. function display()
2. {
3. document.writeln(10+20+"30");
4. }
5. display();
1. function display()
2. {
3. document.writeln("10"+20+30);
4. }
5. display();
The storage of cookies on the hard disk depends on the OS and the
browser.
1. <script>
2. window.document.body.style.cursor = "wait";
3. </script>
37) Are Java and JavaScript same?No, Java and JavaScript are the two
different languages. Java is a robust, secured and object-oriented
programming language whereas JavaScript is a client-side scripting
language with some limitations.
1. var num=-5;
2. function display()
3. {
4. document.writeln(num/0);
5. }
6. display();
• Alert Box
• Confirm Box
• Prompt Box
1. <script type="text/javascript">
2. function msg(){
3. alert("Hello Alert Box");
4. }
5. </script>
6. <input type="button" value="click" onclick="msg()"/>
1. <script type="text/javascript">
2. function msg(){
3. var v= confirm("Are u sure?");
4. if(v==true){
5. alert("ok");
6. }
7. else{
8. alert("cancel");
9. }
10.
11. }
12. </script>
13.
14. <input type="button" value="delete record" onclick="msg(
)"/>
1. <script type="text/javascript">
2. function msg(){
3. var v= prompt("Who are you?");
4. alert("I am "+v);
5.
6. }
7. </script>
8.
9. <input type="button" value="click" onclick="msg()"/>
Let's see the JavaScript code to submit the form by clicking the link.
1. <script type="text/javascript">
2. document.body.bgColor="pink";
3. </script>
1. <script>
2. function validateform(){
3. var name=document.myform.name.value;
4. var password=document.myform.password.value;
5.
6. if (name==null || name==""){
7. alert("Name can't be blank");
8. return false;
9. }else if(password.length<6){
10. alert("Password must be at least 6 characters long.");
11. return false;
12. }
13. }
14. </script>
15. <body>
16. <form name="myform" method="post" action="abc.jsp" o
nsubmit="return validateform()" >
17. Name: <input type="text" name="name"><br/>
18. Password: <input type="password" name="password"><b
r/>
19. <input type="submit" value="register">
20. </form>
1. <script>
2. function validateemail()
3. {
4. var x=document.myform.email.value;
5. var atposition=x.indexOf("@");
6. var dotposition=x.lastIndexOf(".");
7. if (atposition<1 || dotposition<atposition+2 || dotposition+2>=
x.length){
1. var address=
2. {
3. company:"phpbotcamp",
4. city:"singapore",
5. state:"UP",
6. fullAddress:function()
7. {
8. return this.company+" "+this.city+" "+this.state;
9. }
10. };
11. var fetch=address.fullAddress();
12. document.writeln(fetch);
1. function display()
2. {
3. x = 10;
4. y = 15;
5. z = x + y;
6. debugger;
7. document.write(z);
8. document.write(a);
9. }
10. display();
For example:
"use strict";
x=10;
console.log(x);
function display1()
document.writeln(Math.random());
display1();
The JavaScript date object can be used to get a year, month and day.
You can display a timer on the webpage by the help of JavaScript
date object.
function display()
var day=date.getDate();
var month=date.getMonth()+1;
var year=date.getFullYear();
display();
function display()
display();
The JavaScript Set object is used to store the elements with unique
values. The values can be of any type i.e. whether primitive values or
object references.
For example:
function display3() {
display3();
function display()
map.set(1,"jQuery");
map.set(2,"AngularJS");
map.set(3,"Bootstrap");
document.writeln(map.get(1)+"<br>");
document.writeln(map.get(2)+"<br>");
document.writeln(map.get(3));
display();
function display()
wm.set(obj1, "jQuery");
wm.set(obj2, "AngularJS");
wm.set(obj3,"Bootstrap");
document.writeln(wm.has(obj2));
display();
<script>
var uri="my test.asp?name=ståle&car=saab";
document.write(encodeURI(uri)+ "<br>");
document.write(decodeURI(uri));
</script>
Output -
my%20test.asp?name=st%C3%A5le&car=saab
my test.asp?name=ståle&car=saab
For Example:
<script>
document.write(escape("Hello? How are you!"));
</script>
Output: Hello%3F%20How%20are%20you%21
<script>
document.write(unescape("Hello%3F%20How%20are%20you
%21"));
</script>
The function .call() and .apply() are very similar in their usage except
a little difference. .call() is used when the number of the function's
arguments are known to the programmer, as they have to be
mentioned as arguments in the call statement. On the other hand,
.apply() is used when the number is not known. The function .apply()
expects the argument to be an array.
var someObject = {
myProperty : 'Foo',
myProperty : 'Bar'
};
someObject.myMethod.call(someOtherObject, '<', '>'); // alerts
'<Bar>'
The 'And' Operator (&&), 'Or' Operator (||) and the 'Not' Operator (!)
can be used in JavaScript.
This can be done by including the name of the required frame in the
hyperlink using the 'target' attribute.
Break statement is used to come out of the current loop while the
continue statement continues the current loop with a new
recurrence.
Both web-garden and web-farm are web hosting systems. The only
difference is that web-garden is a setup that includes many
processors in a single server while web-farm is a larger setup that
uses more than one server.
fh = fopen(getScriptPath(), 0);
DOM stands for Document Object Model and is responsible for how
various objects in a document interact with each other. DOM is
required for developing web pages, which includes objects like
paragraph, links, etc. These objects can be operated to include
actions like add or delete. DOM is also required to add extra
capabilities to a web page. On top of that, the use of API gives an
advantage over other existing models.
Events are the actions that result from activities, such as clicking a
link or filling a form, by the user. An event handler is required to
manage proper execution of all these events. Event handlers are an
extra attribute of the object. This attribute includes event's name and
the action taken if the event takes place.
No. JavaScript does not have concept level scope. The variable
declared inside the function has scope inside the function.
They are as –
• Primitive
• Reference types.
Primitive types are number and Boolean data types. Reference types
are more complex types like strings and dates.
Screen objects are used to read the information from the client's
screen. The properties of screen objects are -
[" joseph "," Jane ", " charlie ", " john "]
For Example:
<script>
document.write(escape("Hello? How are you!"));
</script>
Output: Hello%3F%20How%20are%20you%21
<script>
document.write(unescape("Hello%3F%20How%20are%20you
%21"));
</script>
<script>
var uri="my test.asp?name=ståle&car=saab";
document.write(encodeURI(uri)+ "<br>");
document.write(decodeURI(uri));
</script>
Output -
my%20test.asp?name=st%C3%A5le&car=saab
my test.asp?name=ståle&car=saab
ECMA Script are like rules and guideline while Javascript is a scripting
language used for web development.
85) How can JavaScript codes be hidden from old browsers that
don't support JavaScript?
Add "<!--" without the quotes in the code just after the <script> tag.
Add "//-->" without the quotes in the code just before the <script>
tag.
Old browsers will now treat this JavaScript code as a long HTML
comment. While, a browser that supports JavaScript, will take the "<!-
-" and "//-->" as one-line comments.
4. PHP
4. PHP
2) What is PHP?
Software in which the source codes are freely used, modify, and
shared by anyone are called Open Source Software. These can also
be distributed under licenses that adhere with the Open Source
Definition.
GET and POST are used to send information from client browser to
web server. In case of GET the information is send via GET method in
name/value pair and is URL encoded. The default GET has a limit of
512.
Java script submit() function is used for submit form without submit
button on click call document.formname.submit()
11) In how many ways we can retrieve the data in the result set
of MySQL using PHP?
We can do it by 4 Ways
mysql_fetch_row.
mysql_fetch_array
mysql_fetch_object
mysql_fetch_assoc
13) What are the differences between Get and post methods.
1. GET Method have some limit like only 2Kb data able to send for
request. But in POST method unlimited data can we send
2. when we use GET method requested data show in url but Not in
POST method so POST method is good for send sensetive request
preg_match(“/^http:\/\/.+@(.+)$/”,”http://[email protected]”,$matches);
echo $matches[1];
Both include and require used to include a file but when included file
not found Include send Warning where as Require send Fatal Error .
Yes we can use include(“xyz.php”) more than one time in any page.
but it create a prob when xyz.php file contain some funtions
declaration then error will come for already declared function in this
file else not a prob like if you want to show same content two time in
page then must incude it two time not a prob
.frm file stores the table format. The data file has an .MYD (MYData)
extension. The index file has an .MYI (MYIndex) extension.)
3. Merge
6. EXAMPLE
9. CSV (The CSV storage engine stores data in text files using comma-
separated values format.)
Just run the PHP CLI (Command Line Interface) program and provide
the PHP script file name as the command line argument.
21) Suppose your Zend engine supports the mode Then how can
u configure your PHP Zend engine to support mode?
In php.ini file:
set
short_open_tag=on
If the file is not found by require(), it will cause a fatal error and halt
the execution of the script. If the file is not found by include(), a
warning will be issued, but execution will continue.
We can send 1024 bytes using GET method but POST method can
transfer large amount of data and POST is the secure method than
GET method.
It’s how they handle failures. If the file is not found by require(), it will
cause a fatal error and halt the execution of the script. If the file is
not found by include(), a warning will be issued, but execution will
continue.
eg : echo $_COOKIE[“user”];
for,while,do while and foreach (NB: You should learn its usage)
mysql_connect(servername,username,password);
mysql_select_db($db_name);
$result = mysql_fetch_array($my_qry);
echo $result[‘First_name’];
while($result = mysql_fetch_array($my_qry))
echo $result[‘First_name’.].”
”;
45) How we can retrieve the data in the result set of MySQL
using PHP?
mysql_fetch_row
mysql_fetch_array
mysql_fetch_object
mysql_fetch_assoc
index.php is the default name of the home page in php based sites.
51) What are the reasons for selecting lamp (Linux, apache,
MySQL, PHP) instead of combination of other software
programs, servers and operating systems?
All of those are open source resource. Security of Linux is very very
more than windows. Apache is a better server that IIS both in
functionality and security. MySQL is world most popular open source
database. PHP is more faster that asp or any other scripting
language.
53) How can we encrypt the username and password using PHP?
Encryption Decryption
AES_ENCRYT() AES_DECRYPT()
ENCODE() DECODE()
DES_ENCRYPT() DES_DECRYPT()
Private: Private limits visibility only to the class that defines the item.
Three are three types of errors:1. Notices: These are trivial, non-
critical errors that PHP encounters while executing a script – for
example, accessing a variable that has not yet been defined. By
default, such errors are not displayed to the user at all – although,
as you
3. Fatal errors: These are critical errors – for example, instantiating
an object of a non-existent class, or calling a non-existent function.
These errors cause the immediate termination
$email= ‘[email protected]’;
60) What are the differences between PHP 3 and PHP 4 and
PHP5?
1>Php3 is oldest version after that php4 came and current version is
php5 (php5.3) where php6 have to come
6 Finality : can now use the final keyword to indicate that a method
cannot be overridden by a child. You can also declare an entire class
as final which prevents it from having any children at all.
8 Passed by Reference :
there are lots of tools available for asp to PHP conversion. you can
search Google for that. the best one is available at
http://asp2php.naken.cc./
63) How can we get second of the current time using date
function?
$second = date(“s”);
‘, date(DATE_RFC1123, $stamp) ,’
‘;?>
same way that the posted data from a WWW form is encoded, that is
the same way as in
$_SESSION[‘name’] = “sonia”;
68) How can we get the properties (size, type, width, height) of
an image using PHP image functions?
By using
$_SERVER[‘HTTP_USER_AGENT’]
variable.
72) How can we take a backup of a MySQL table and how can we
restore it?
first of all instead of using select * from table1, use select column1,
column2, column3.. from table1 Look for the opportunity to
introduce index in the table you
are querying.use limit keyword if you are looking for any specific
number of rows from the result set.
74) How many ways can we get the value of current session id?
75) How can we destroy the session, how can we unset the
variable of a session?
78) How many ways we can pass the variable through the
navigation
GET/QueryString
POST
Sort(), arsort(),
asort(), ksort(),
natsort(), natcasesort(),
rsort(), usort(),
array_multisort(), and
uksort().
2 ways
b) count($urarray)
84) List out some tools through which we can draw E-R diagrams
for mysql.
Case Studio
Smart Draw
85) How can I retrieve values from one database server and
store them in other database server using PHP?
we can always fetch from one database and rewrite to another. here
is a nice solution of it.
$db1 = mysql_connect(“host”,”user”,”pwd”)
mysql_select_db(“db1”, $db1);
$res1 = mysql_query(“query”,$db1);$db2 =
mysql_connect(“host”,”user”,”pwd”)
mysql_select_db(“db2”, $db2);
i.e $res1 – But you cannot execute new query in $db1, even if you
supply the link as because the link was overwritten by the new db.so
that?
$db1 = mysql_connect(“host”,”user”,”pwd”)
mysql_select_db(“db1”, $db1);
$res1 = mysql_query(“query”,$db1);
mysql_select_db(“db2”, $db2);
$res2 = mysql_query(“query”,$db2);
$db2 with this optional parameter set to ‘true’, so both link will
remain live.
$res3 = mysql_query(“query”,$db1);
Directory
stdClass
__PHP_Incomplete_Class
exception
php_user_filter
You can maintain two separate language file for each of the
language. all the labels are putted in both language files as variables
and assign those variables in the PHP source. on runtime choose the
required language option.
Abstract class: abstract classes are the class where one or more
methods are abstract but not necessarily all method has to be
abstract.
Abstract methods are the methods, which are declare in its class but
not define. The definition of those methods must be in its extending
Interface class: Interfaces are one type of class where all the
methods are abstract. That means all the methods only declared but
not defined.
via JavaScript to prompt for an email to send. this requires the client
to approve it.
to keep re-issuing the entire query but can refer to the stored
procedure.
Without an index, MySQL must begin with the first row and then
read through the entire table to find the relevant rows. The larger
the table, the more this costs. If the table has an index for the
columns in question, MySQL can quickly determine the position to
seek to in the middle of the data file without having to look at all the
data. If a table has 1,000 rows, this is at least 100 times faster than
reading sequentially. If you need to access most of the rows, it is
faster to
The following table describes the maximum length for each type of
identifier.
Database 64
Table 64
Column 64
Index 64
Alias 255
94) How many values can the SET function of MySQL take?
MySQL set can take zero or more values but at the maximum it can
take 64 values
describe Table-Name;
96) How many tables will create when we create table, what are
they?
Each MyISAM table is stored on disk in three files. The files have
names that begin with the table name and have an extension to
indicate
within a tablespace that can be created from several files. This allows
a table to exceed the maximum individual file size. The tablespace
can include raw disk partitions, which allows extremely large tables.
The maximum tablespace size is 64TB.
4GB)
IDENTIFIED BY [password]
a) All privileges
a) All privileges
Second Normal Form Where the First Normal Form deals with
redundancy of data across a
horizontal row, Second Normal Form (or 2NF) deals with redundancy
of data in vertical columns. As stated earlier, the normal forms are
progressive, so to achieve Second Normal Form, your tables must
already be in First Normal Form.
102) How can we find the number of rows in a result set using
PHP?
$num_rows = mysql_num_rows($result);
103) How many ways we can we find the current date using
MySQL?
SELECT CURDATE();
CURRENT_DATE() = CURDATE()
SELECT CURTIME();
CURRENT_TIME() = CURTIME()
Advantages
Disadvantages
This method can not control styles for multiple documents at once
Inline Styles
Advantages
Disadvantages
Unique Key: Unique Keys are used to uniquely identify each row in
the table. There can be one and only one row for each unique key
value.
So NULL can be a unique key.There can be only one primary key for
a table but there can be more
Set char to occupy n bytes and it will take n bytes even if u r storing a
value of n-m bytes Set varchar to occupy n bytes and it will take only
the required space and will not use the n bytes
111) How can I load data from a text file into a table?
you can use LOAD DATA INFILE file_name; syntax to load data from a
text file. but you have to make sure that
a) data is delimited
112) How can we know the number of days between two given
dates using MySQL?
SELECT DATEDIFF(“2007-03-07″,”2005-01-01”);
113) How can we know the number of days between two given
dates using PHP?
$date1 = date(“Y-m-d”);
$date2 = “2006-08-15”;
by using spl_autoload_register(‘autoloader::funtion’);
Like below
class autoloader
$path = $_SERVER[‘DOCUMENT_ROOT’] .
“/dataobjects/{$class}.php”;
spl_autoload_register(‘autoloader::includesautoloader’);
spl_autoload_register(‘autoloader::daoautoloader’);
spl_autoload_register(‘autoloader::moduleautoloader’);
if (!empty($this->readReceipt)) {
>__formatAddress($this->readReceipt) . $this->_newLine;
117) how to track user logged out or not? when user is idle ?
As the session will exist longer as till browser closes. The default
behaviour for sessions is to keep a session open indefinitely and only
to expire a session when the browser is closed.
This behaviour can be changed in the php.ini file by altering the line
session.cookie_lifetime = 0 to a value in seconds.
If you wanted the session to finish in 5 minutes you would set this to
session.cookie_lifetime = 300 and restart your httpd server.
The PDF functions in PHP can create PDF files using the PDFlib library
With version 6, PDFlib offers an object-oriented API for PHP 5 in
addition to the function-oriented API for PHP 4. There is also the »
Panda module. FPDF is a PHP class which allows to generate PDF files
with pure PHP, that is to say without using the PDFlib library. F from
FPDF stands for Free: you may use it for any kind of usage and
modify it to suit your needs. FPDF requires no extension (except zlib
to activate compression and GD for GIF support) and works with
PHP4 and PHP5.
Magic methods are the members functions that is available to all the
instance of class Magic methods always starts with “__”. Eg.
__construct All magic methods needs to be declared as public To use
magic method they should be defined within the class or program
scope Various Magic Methods used in PHP 5 are: __construct()
Using URL rewriting we can convert dynamic URl to static URL Static
URLs are known to be better than Dynamic URLs because of a
number of reasons
3. Static URLs are always more friendlier looking to the End Users.
along with this we can use URL rewriting in adding variables [cookies]
to the URL to handle the sessions.
5. For protected areas, use sessions or validate the login every time.
6. If you don’t want the file contents to be seen, give the file a .php
extension.
The SQL Server Driver for PHP v1.0 is designed to enable reliable,
scalable integration with SQL Server for PHP applications deployed
on the Windows platform. The Driver for PHP is a PHP 5 extension
that
allows the reading and writing of SQL Server data from within PHP
scripts. using MSSQL or ODBC modules we can access Microsoft SQL
server
curl is a command line tool for transferring files with URL syntax,
supporting FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT,
LDAP, LDAPS and FILE. curl supports SSL certificates, HTTP
POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies,
cookies, user+password authentication (Basic, Digest, NTLM,
Negotiate, kerberos…), file transfer resume, proxy tunneling and a
busload of other useful tricks.
While PDO has its advantages, such as a clean, simple, portable API
but its main disadvantage is that it doesn’t allow you to use all of the
advanced features that are available in the latest versions of MySQL
server. For example, PDO does not allow you to use MySQL’s
Just need to use below code for connect mysql using PDO
try {
$password);
catch(PDOException $e)
echo $e->getMessage();
=>Object-oriented interface
They are both variables. But $var is a variable with a fixed name.
$$var is a variable who’s name is stored in $var. For example, if $var
contains “message”, $$var is the same as $message.
WordPress
Joomla
Magento
Drupal etc.
CakePHP
CodeIgniter
Yii 2
Symfony
Spaceship operator
Anonymous classes
Closure::call method
Generator delegation
Syntax: $variableName=value;
PHP data types are used to hold different types of data or values.
There are 8 primitive data types which are further categorized in 3
types:
Scalar types
Compound types
Special types
PHP multi line comment is done by enclosing all lines within /* */.
The PHP count() function is used to count total elements in the array,
or something an object.
The isset() function checks if the variable is defined and not null.
Indexed array
Associative array
Multidimensional array
array()
array_change_key_case()
array_chunk()
count()
sort()
array_reverse()
array_search()
array_intersect()
$season=array(“summer”,”winter”,”spring”,”autumn”);
$salary=array(“Sonoo”=>”350000″,”John”=>”450000″,”Kartik”=>”20000
0”);
strtolower()
strtoupper()
ucfirst()
lcfirst()
ucwords()
strrev()
strlen()
You can use JavaScript submit() function to submit the form without
explicitly clicking any submit button.
PHP allows you to include file so that page content can be reused
again. There are two ways to include file in PHP.
1.include
2.require
Require and include both are used to include a file, but if file is not
found include sends warning whereas require sends Fatal error.
Syntax:
Syntax: $variableName=value;
PHP data types are used to hold different types of data or values.
There are 8 primitive data types which are further categorized in 3
types:
Scalar types
Compound types
Special types
PHP multi line comment is done by enclosing all lines within /* */.
The PHP count() function is used to count total elements in the array,
or something an object.
The isset() function checks if the variable is defined and not null.
Indexed array
Associative array
Multidimensional array
array()
array_change_key_case()
array_chunk()
count()
sort()
array_reverse()
array_search()
array_intersect()
$season=array(“summer”,”winter”,”spring”,”autumn”);
$salary=array(“Sonoo”=>”350000″,”John”=>”450000″,”Kartik”=>”20000
0”);
strtolower()
strtoupper()
ucfirst()
lcfirst()
ucwords()
strrev()
strlen()
You can use JavaScript submit() function to submit the form without
explicitly clicking any submit button.
PHP allows you to include file so that page content can be reused
again. There are two ways to include file in PHP.
1.include
2.require
Require and include both are used to include a file, but if file is not
found include sends warning whereas require sends Fatal error.
Syntax:
Syntax:
PHP provides various functions to read data from file. There are
different functions that allow you to read all file data, read data line
by line and read data character by character.
fread()
fgets()
fgetc()
PHP fwrite() and fputs() functions are used to write data into file. To
write data into file, you need to use w, r+, w+, x, x+, c or c+ mode.
You should just run the PHP command line interface (CLI) and specify
the file name of the script to be executed as follows.
bool mail($to,$subject,$message,$header);
mysqli_query()
PDO::_query()
$_SERVER[“REMOTE_ADDR”];
They both include a specific file but on require the process exits with
a fatal error if the file can’t be included, while include statement may
still pass and jump to the next step in the execution.
201) Explain how you can update Memcached when you make
changes to PHP?
Resetting the Cache: It is similar to the first method but rather than
just deleting the keys and waiting for the next request for the data to
refresh the cache, reset the values after the insert or update.
205) What are the three classes of errors that can occur in PHP?
statement
The goto statement can be placed to enable jumping inside the PHP
program. The target is pointed by a label followed by a colon, and
the instruction is specified as a goto statement followed by the
desired target label.
__sleep returns the array of all the variables that need to be saved,
while __wakeup retrieves them..
These opcodes are executed, and the HTML generated is sent to the
client.
The PDF functions in PHP can create PDF files using the PDFlib library
Version 6. PDFlib offers an object-oriented API for PHP 5 in addition
to the function-oriented API for PHP 4.
There is also the » Panda module. FPDF is a PHP class, which allows
generating PDF files with pure PHP (without using the PDFlib library.)
F from FPDF stands for Free: you may use it for any kind of usage
and modify it to suit your needs. FPDF requires no extension (except
zlib to activate compression and GD for GIF support) and works with
PHP4 and PHP5.
added Closure::call()
server. This is because modifying the execution time will affect all the
sites hosted by the server.
The default limit is 30 seconds. The time limit can be set to zero to
impose no time limit to pause.
soundex()
$str= “hello”;
Echo soundex($str);
?>
metaphone()
echo metaphone(“world”);
?>
Just run the PHP CLI (Command Line Interface) program and provide
the PHP script file name as the command line argument. For
example, “php myScript.php”, assuming “php” is the command to
invoke the CLI program.
Remember that if your PHP script was written for the Web CGI
interface, it may not execute properly in command line environment.
To scrap the data from website, Website must be public and open for
scrapable.
$ch = curl_init();
$output = curl_exec($ch);
curl_close($ch);
echo $output;
Example:
$var1 = ‘Variable 1’
$$var1= ‘variable2’
$var1 $($var1)
Example
$Message = “YOU”;
$you= “Me”;
Syntax:
Syntax:
memory allocation
$startTime= microtime(true);
$endTime= microtime(true);
247) In how many ways can you retrieve data in the result set of
MySQL using PHP? What is the difference between
mysql_fetch_object and mysql_fetch_array?
We can retrieve data in the result set of MySQL using PHP in four
Ways
Once the Web server received the uploaded file, it will call the PHP
script specified in the form action attribute to process them. This
received PHP script can get the uploaded file information through a
predefined array called $_FILES. Uploaded file information is
organized in $_FILES as a two-dimensional array as:
5. MySQL
5. MySQL
1) What's Mysql ?
If you look at the large variety of SQL commands, they can be divided
into three large subgroups. Data Definition Language deals with
database schemas and descriptions of how the data should reside in
the database, therefore language statements like CREATE TABLE or
ALTER TABLE belong to DDL. DML deals with data manipulation, and
therefore includes most common SQL statements such SELECT,
INSERT, etc. Data Control Language includes commands such as
GRANT, and mostly concerns with rights, permissions and other
controls of the database system.
SELECT COUNT (user_id) FROM users would only return the number
of user_id’s.
SELECT book_title FROM books LIMIT 25, 100. The first number in
LIMIT is the offset, the second is the number.
7) How Would You Write A Query To Select All Teams That Won
Either 2, 4, 6 Or 8 Games?
8) How Would You Select All The Users, Whose Phone Number Is
Null?
10) How Do You Find Out Which Auto Increment Was Assigned
On The Last Insert?
What it means is that so of the data that you’re trying to delete is still
alive in another table. Like if you have a table for universities and a
table for students, which contains the ID of the university they go to,
running a delete on a university table will fail if the students table still
contains people enrolled at that university. Proper way to do it would
be to delete the offending data first, and then delete the university in
question. Quick way would involve running SET foreign_key_checks=0
before the DELETE command, and setting the parameter back to 1
after the DELETE is done. If your foreign key was formulated with ON
DELETE CASCADE, the data in dependent tables will be removed
automatically.
14) How Can You See All Indexes Defined For A Table?
18) When You Create A Table, And Then Run Show Create Table
On It, You Occasionally Get Different Results Than What You
Typed In. What Does Mysql Modify In Your Newly Created
Tables?
The first is, naturally, the character count. The second is byte count.
For the Latin characters the numbers are the same, but they’re not
the same for Unicode and other encodings.
You can limit the possible values that go into the table. CREATE
TABLE months (month ENUM ‘January’, ‘February’, ‘March’,…); INSERT
months VALUES (’April’);
/etc/init.d/mysql start.
41) Have You Ever Used Mysql Administrator And Mysql Query
Browser?
In MyISAM static all the fields have fixed width. The Dynamic MyISAM
table would include fields such as TEXT, BLOB, etc. to accommodate
the data types with various lengths. MyISAM Static would be easier to
restore in case of corruption, since even though you might lose some
data, you know exactly where to look for the beginning of the next
record.
HEAP tables are in-memory. They are usually used for high-speed
temporary storage. No TEXT or
BLOB fields are allowed within HEAP tables. You can only use the
comparison operators = and <=>. HEAP tables do not support
AUTO_INCREMENT. Indexes must be NOT NULL.
Those are the special tables, data for which is saved into comma-
separated values files. They cannot be indexed.
Prior to MySQL 5.0.3: those are all synonyms. After MySQL 5.0.3: BIT
data type can store 8 bytes of data and should be used for binary
data.
FLOATs store floating point numbers with 8 place accuracy and take
up 4 bytes.
55) If You Specify The Data Type As Decimal (5,2), What's The
Range Of Values That Can Go In This Table?
999.99 to -99.99. Note that with the negative number the minus sign
is considered one of the digits.
That field gets the current timestamp whenever the row gets altered.
57) But What If You Really Want To Store The Timestamp Data,
Such As The Publication Date Of The Article?
Create two columns of type TIMESTAMP and use the second one for
your real data.
MySQL is very fast, reliable, and easy to use. If that is what you are
looking for, you should give it a try. MySQL also has a very practical
set of features developed in very close cooperation with our users.
You can find a performance comparison of MySQL to some other
database managers on our benchmark page. See section 12.7 Using
Your Own Benchmarks. MySQL was originally developed to handle
very large databases much faster than existing solutions and has
been successfully used in highly demanding production
environments for several years. Though under constant
development, MySQL today offers a rich and very useful set of
functions. The connectivity, speed, and security make MySQL highly
suited for accessing databases on the Internet.
If you don't use columns from all used tables, MySQL will stop the
scanning of the not used tables as soon as it has found the first
match.
In some cases MySQL will handle the query differently when you are
using LIMIT # and not using HAVING:
If you are selecting only a few rows with LIMIT, MySQL will use
indexes in some cases when it normally would prefer to do a full
table scan.
If you use LIMIT # with ORDER BY, MySQL will end the sorting as
soon as it has found the first # lines instead of sorting the whole
table.
As soon as MySQL has sent the first # rows to the client, it will abort
the query.
LIMIT 0 will always quickly return an empty set. This is useful to check
the query and to get the column types of the result columns.
The size of temporary tables uses the LIMIT # to calculate how much
space is needed to resolve the query.
If you want to delete all rows in the table, you should use TRUNCATE
TABLE table_name. The time to delete a record is exactly
proportional to the number of indexes. To delete records more
quickly, you can increase the size of the index cache.
ISAM : same
HEAP : Fast data access, but will loose data if there is a crash. Cannot
have BLOB, TEXT & AUTO INCRIMENT fields
id name
103 Schmitt
112 King
114 Ferguson
119 Labrune
121 Bergulfsen
Both CHAR and NCHAR are fixed length string data types. But they
have the following differences:
• Both CHAR and NCHAR columns are defined with fixed lengths
in units of characters.
If you want to enter characters as HEX numbers, you can quote HEX
numbers with single quotes and a prefix of (X), or just prefix HEX
1
SELECT 3 NOT IN (1,2,3,4,5) FROM DUAL;
0
SELECT Y’ IN (‘F’,’Y’,I) FROM DUAL;
1
A LIKE condition is also called pattern patch. There are 3 main rules
on using LIKE condition:
If you have a table with a lots of rows, and you know that one of the
columns will be used often as a search criteria, you can add an index
for that column to improve the search performance. To add an
index, you can use the “CREATE INDEX” statement as shown in the
following script:
If you want to see the index you have just created for an existing
table, you can use the “SHOW INDEX FROM tableName” command to
get a list of all indexes in a given table.
If you don’t need an existing index any more, you should delete it
with the “DROP INDEX indexName ON tableName” statement. Here
is an example SQL script :
If you have an existing view, and you dont want it anymore, you can
delete it by using the “DROP VIEW viewName” statement
6. WORDPRESS
1) What is WordPress?
WordPress is safe and secure to operate. You need not worry about
anything but, still, it is suggested to update your site with latest
WordPress version to avoid hacking.
• Using several plugins can make the website heavy to load and
run.
• PHP knowledge is required to make modifications or changes
in the WordPress website.
• Sometimes software needs to be updated to keep the
WordPress up-to-date with the current browsers and mobile
devices. Updating WordPress version leads to loss of data, so a
backup copy of the website is required.
• Modifying and formatting the graphic images and tables is
difficult.
• Web Server -
o WAMP (Windows)
o LAMP (Linux)
o XAMP (Multi-platform)
o MAMP (Macintosh)
• Operating System - Cross-platform
• Browser Support - IE (Internet Explorer 8+), Firefox, Google
Chrome, Safari, Opera
• PHP Compatibility - PHP 5.2+
WordPress has an inbuilt SEO search engine benefit. You can also
have an additional plug-in in WordPress to help with SEO and rank
on a favorite search engine like Google.
Here 23 specifies the octal 23 and x23 determine the hex 23.
Filter hooks: Filter hooks facilitate you to add content or text at the
end of the post.
• Flexibility
• Multilingual- available in more than 70 languages
• Own data- no unwanted advert on your website
• Flexibility and Easy publishing option.
• Open source
• Extremely fast
• A widely available database server
• Supported by low-cost Linux hosting
• wp_commentmeta
• wp_comments
• wp_links
• wp_options
• wp_postmeta
• wp_posts
• wp_terms
• wp_term_relationships
• wp_term_taxonomy
• wp_usermeta
• wp_users
Parents:: constructor($value)
19) Is WordPress the best CMS or any other CMS is better than
WordPress?
Posts allow you to write a blog and post it on your site. They are
listed in reverse chronological order on the front page of your blog.
Pages are different from posts. They are static, and they do not
change often. You can add pages containing information about you
and your site.
WordPress uses PHP codes to display posts. This PHP code is known
as a loop.
You can edit WordPress comment using the dashboard. From the
panel, under the Comments option, select edit to edit a comment.
If you don't want a comment from a new user on your blog, check
the option "Users must be registered and logged in to comment"
from Discussions under the Settings option.
30) How can you handle the situation if your WordPress site is
hacked?
With the help of tags, similar posts can be grouped. Hence, it makes
more comfortable for the users to search for a particular post. Tags
are similar to categories but still different.
WordPress Tags are like categories, but they are used to describe a
post more specifically. Tags are not necessary for every post.
With the help of a WordPress theme, you can design the layout and
appearance of your website in the front-end.
41) When will you not be able to see the plugin menu on a
WordPress site?
42) What are the plugins you can use to create a contact form in
WordPress?
You can use a plug-in like Gravity forms or a free plugin contact form
7 to create a contact form in WordPress.
• One-click update
• Manually update
• Choosing a host
• Strong password
• 2 step login authentication
• Limit number of login attempts
• Use SSL
Optimization increases the speed of your site and gives the best
possible outcome. It improves the ranking of a website.
• Use CDN
• Use a caching plugin
• Use a simple theme/framework
• Keep site updated
• Split long posts into smaller pages
Template tags are used within themes to retrieve content from your
database. It is a piece of code that tells WordPress to get something
from the database.
Custom fields are also called post meta. It is a feature through which
users can add arbitrary information when writing a post. These
metadata can be displayed using template tags in WordPress
themes.
A backup is just the copy of your original site through which you can
restore your original site if anything goes wrong. Keeping a backup
on the safe side is always advisable.
Backup allows you to retrieve your site back if something goes wrong
or if your site breaks. There could be many reasons for this like
external attack, hacking, server down.
You can lose everything from data to all the posts on your site. The
backup is essential to avoid it.
There are many files in your WordPress directory. These files can be
downloaded back from wordpress.org site. Some of them can be
retrieved back but some can't.
Both the above files can't be replaced by other default files. Hence,
they need to be backed up.
In the database, all your posts, media files, comments, and metadata
stored. It also contains user's information and all your plugin
settings. All these information are personal and unique. If you lose
them, they are gone permanently. Select your WordPress database
(which you created during the installation of WordPress).
• Click on Export.
• Quick is used when the database is small. Custom is used when
the database is large. Suppose we are choosing Custom.
• After choosing Custom, a table appears. Select all the tables.
• Now come to the Output section.
• Choose SQL from the Format drop-down menu.
The GNU General Public License is called GPL in short. It has some
terms and conditions to copy, modify and distribute the software
licensed under its name.
GNU makes sure that any software source-code licensed under it has
to make originating source code open and freely available to all its
users. Here, freely doesn't mean by cost but it says that it is freely
available to users to distribute and modify the code, but they can't
impose any restrictions on further distribution, the source code has
to be made available.
61) From SEO point of view is WordPress helpful? Will it show the
website on Google?
63) What are the types of hooks in WordPress and mention their
functions?
66) What are the rules that you have to follow for WordPress
plugin development?
After making the changes, you can rename the folder or directory
with the WordPress file in it.
73) What are the steps you can take if your WordPress file is
hacked?
You can’t see your plugin menu when the blog is hosted on free
wordpress.com as you cannot add plugin there. Also, if you do not
have an account of an administrator level on your WordPress is not
possible to see the plugin.
This would likely happen when you have pasted the code from a
website with wrong formats, also when you have pasted the code in
an incorrect location. It may also happen when your IP is banned
79) What are the plugins you can use to create a contact form in
WordPress?
Most of the things are similar in both except the choices of themes
and the use of plugins.
86) What are the essential features you look for a theme?
It depends on the type of the site or project, but yes one can update
their own content on the site.
93) What should one use for plugin development — custom post
types or custom database tables?
94) Can you host WordPress using Amazon web services such as
EC2, RDS, EBS, etc.?
96) What are the reasons why one should not hack WordPress
core file?
The best reason not to hack the core files is that whatever you might
be doing has to be reworked as a patch.