You are on page 1of 43

Course Title:

3/6/2019
Advanced Web Programming Lab
CourseNo:MCA17303CR

NIELIT
Name:________________________
Roll no:_______________________

Signature
1. Create a html page with demonstrates the use of formatting tags image tags and other
basic tags.
<html>
<head>
<title>formating_tags</title>
<style>
body{
background-color: black;
color: bisque;
font-size: 24px;
}
</style>
</head>
<body>
<h1>The text is used to implement various formatting tags</h1></br>
<b>XHTML stands for EXtensible HyperText Markup Language. </b> </br>
<strong>The XHTML 1.0 is the first document type in the XHTML family.</strong>
<i>XHTML documents can be written to operate .</i>
<em>better than they did before in existing browsers as well as in new browsers</em>
<h2>HTML <small>Small</small> Formatting</h2></br>
<h2>XHTML was developed by <mark>World Wide Web Consortium (W3C)</mark>
</h2>
<p>My favorite <ins>color</ins> is red.</p>
<p> This is <sup>superscripted</sup> text.</p>
</body>
</html>

2. Create the different types of list in html


<!DOCTYPE html>
<html>
<head>
<title>dropdown</title>
</head>
<body>
<ul>
<li><a href="#">HTML</a></li>
<li><a href="#">CSS</a></li>
<li><a href="#">JavaScript</a></li>
<li><a href="#">Content Management</a>
</ul>
<ol>
<li><a href="#">Joomla</a></li>
<li><a href="#">Drupal</a></li>
<li><a href="#">WordPress</a></li>
<li><a href="#">Concrete 5</a></li>
</ol>
</body>
</html>

3. Create a table with the relevant tags and attributes


<!DOCTYPE html>
<html>
<head>
<title>testtable</title>
</head>
<body>
<table border="3" bordercolor=blue cellspacing="5" cellpadding="50" align=center>
<caption style="color: blue; font-family: times new roman; font-size: 33px;">simple table
</caption>
<tr>
<td>row 1/column 1</td>
<td>row 1/column 2</td> <td>row 1/column 3</td>
</tr>
<tr>
<td>row 2/column 1</td>
<td>row 2/column 2</td>
<td>row 2/column 3</td>
</tr>
</table>
</body>
</html>

4. Create a html form in the table layout covering major form elements
<html>
<head>
<title > Registration_from </title>
<link rel="stylesheet" a href="cist.css"

</head>
<body background ="71.jpg">

<center>
<h1> Welcome to Student Registration Form</h1><p>
</center>
<div class="container">
<form method="post" action="loginp.php" ><p>
<br>
Name : <input type="text1" name="text1" placeholder="Enter the Name " border="2"
size="35" ><br><p>
Roll no : <input type="text3" name="text1" ><br><p>
Address :<input type="text3" name="text1" ><p>
Gender <input type="radio" name ="rb"> Male
<input type="radio" name ="rb" checked="checked"> FeMale <p>
<input type="checkbox" name ="c" value="on"> C Programming
<input type="checkbox" name ="web" value="on"> web Programming<p>
Qualification :<select name="qualification">
<option name="MCA" >MCA
<option name="MBA" >MBA
<option name="BCA" >BCA
<option name="ol" selected>O Level
</select>
</div>
<center>
<input type="Submit" name="bt" value="Save" class="myclass">
</center>
</form>
</body>
</html>

5. Create a html page with links in one frame and the linked page opens in the other frame.
6. Make use of tables as the layout of the web page.
Week 4:
1 Create a Navigation bar (with dropdown) with CSS.
<html >
<head>
<style type="text/css">
nav {
display: block;
position: absolute;
top: 0;
width: 100%;
background-color: green;
}
li{
list-style-type: none;
display: inline;
margin-right: 20px;
font-size:25px
}
a:link {
color: #fff;
text-decoration: none;
}
a:hover {
color: orange;
text-decoration: none;
}
li > ul {
display: none
}
li:hover ul {display: block; position: absolute; left:200px;background-
color:green;margin:0;}
li:hover ul li a:link{display: block;margin-left:-30px;}
</style>
</head>
<body>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li>
<a href="#">Products</a>
<ul>
<li><a href="#">Engineering</a></li>
<li><a href="#">Telecom</a></li>
<li><a href="#">Energy</a></li>
<li><a href="#">Finance</a></li>
<li><a href="#">Consultancy</a></li>
</ul>
</li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</body>
</html>
1 CSS Grid
<html >
<head>
<title> create a CSS Grid</title>
<style type="text/css">
.container, .row {
width: 100%;
}
.row:before, .row:after {
display: table;
content: "";
}
.row:after {
clear: both;
}
.col1, .col2, .col3 {
float: left;
width:25.333333333%;
margin:1%;
padding:1%;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col1">
<p>XHTML stands for EXtensible HyperText Markup Language. It is the next step in
the evolution of the internet. The XHTML 1.0 is the first document type in the XHTML
family.p>
</div>
<div class="col2">
<p>XHTML is almost identical to HTML 4.01 with only few differences. This is a
cleaner and stricter version of HTML 4.01. If you already know HTML, then you need to
give little attention to learn this latest version of HTML.</p>
</div>
<div class="col3">
<p>XHTML documents can utilize applications such as scripts and applets that rely upon
either the HTML Document Object Model or the XML Document Object Model.</p>
</div>
</div>
</div>
</body>
</html>

1 CSS based sticky footer.

<html >
<head>
<title> create a sticky footer</title>
<style type="text/css">
.footer {
position:fixed;
bottom:0;
display:block;
width:100%;
background-color: red;
color: #fff;
}
</style>
</head>
<body>
<p>
XHTML defines quality standard for your webpages and if you follow
that,
then your web pages are counted as quality web pages.
The W3C certifies those pages with their quality stamp. </p>
<div class="footer">
<p>I will be stuck here.</p>
</div>
</body>
</html>
2 Create a CSS3 based Zebra striped table,
<html>
<head>
<title>HTML CSS exercise - CSS3 Zebra Striping a Table</title>
<style type="text/css">
table {
border:1px solid silver
}
th {
background-color: #ccc;
}
tbody tr:nth-child(even) {
background-color: #abe113;
}
</style>
</head>
<body>
<table>
<tr><th>Id</th><th>Name</th><th>Major</th></tr>
<tr><td>1001</td><td>Gopl Murthy</td><td>Physics</td></tr>
<tr><td>1002</td><td>Joy Sen</td><td>Economics</td></tr>
<tr><td>1003</td><td>Chandu Yadav</td><td>Chemistry</td></tr>
<tr><td>1004</td><td>Shalini Gupta</td><td>Zoology</td></tr>
<tr><td>1004</td><td>Vivek Kumar</td><td>Math</td></tr>
<tr><td>1004</td><td>Sameer Ali</td><td>Botany</td></tr>
</table>
</body>
</html>
3 CSS3 based button
<!doctype html>
<html>
<head>
<title>HTML CSS Exercise - create button with CSS3</title>
<style>
button {
width: 200px;
padding:8px;
background-color: #428bca;
border-color: #357ebd;
color: #fff;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px; /* future proofing */
-khtml-border-radius: 10px; /* for old Konqueror browsers */
text-align: center;
vertical-align: middle;
border: 1px solid transparent;
font-weight: 900;
font-size:125%
}
</style>
<title>Untitled Document</title>
</head>
<body>
<button>Subscribe Now</button>
</body>
</html>
3 CSS3 image rounded shape
<html>
<head>
<title>HTML CSS Exercise - make an image rounded with CSS3</title>
<style>
.rounded-img {
border-radius: 50%
}
</style>
</head>
<body>
<img data-src="holder.js/140x140" class="rounded-img" alt="140x140" src="muneer.jpg+"
style="width: 140px; height: 140px;">
</body>
</html>
4 Create a stitched look,
<html lang="en">
<head>
<title>Create a Stiched Look with CSS3</title>
<style>
.stitched {
width: 200px;
padding: 20px;
margin: 10px;
background: #0d90df;
color: #fff;
font-size: 21px;
font-weight: bold;
line-height: 1.3em;
border: 2px dashed #fff;
border-radius: 10px;
box-shadow: 0 0 0 4px #0d90df, 2px 1px 6px 4px rgba(10, 10, 0, 0.5);
text-shadow: -1px -1px #aa3030;
font-weight: normal;
}
</style>
</head>
<body>
<div class="stitched"></div>
</body>
</html>
II CSS3 Corner Ribbon,
<html >
<head>
<title>Corner Ribbon with CSS3 Example</title>
<style type="text/css">
.ribbon {
background-color: #a00;
overflow: hidden;
white-space: nowrap;
position: absolute;
left: -50px;
top: 40px;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-box-shadow: 0 0 10px #888;
-moz-box-shadow: 0 0 10px #888;
box-shadow: 0 0 10px #888;
}
.ribbon a {
border: 1px solid #faa;
color: #fff;
display: block;
font: bold 100% 'Helvetica Neue', Helvetica, Arial, sans-serif;
margin: 1px 0;
padding: 10px 50px;
text-align: center;
text-decoration: none;
/* for creating shadow */
text-shadow: 0 0 5px #444;
}
</style>
</head>
<body>
<div class="ribbon">
<a href="#">Best value pack</a>
</div>
</body>
</html>
III CSS3 blurry text effect,
<html>
<head>
<title>Blurry text with CSS3</title>
<style type="text/css">
p{
color:#000000;
font-size:50px;
font-family:arial;
text-shadow: 0 0 3px #000000,
3px 0 3px #000000,
0 3px 3px #000000,
-3px 0 3px #000000,
0 -3px 3px #000000;
}
</style>
</head>
<body>
<p>This text is blurred</p>
</body>
</html>
d.CSS3 speech bubble shape
<html >
<head>
<title>Create a speech bubble shape with CSS3</title>
<style type="text/css">
#speech-bubble {
width: 120px;
height: 80px;
background: #5ac4ed;
position: absolute;
left:100px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
}
#speech-bubble:before {
content:"";
position: absolute;
width: 0;
height: 0;
border-top: 13px solid transparent;
border-right: 26px solid #5ac4ed;
border-bottom: 13px solid transparent;
margin: 13px 0 0 -25px;
}
</style>
</head>
<body>
<div id="speech-bubble"></div>
</body>
</html>
5. Image cross effect with CSS3 transition
<html >
<head>
<meta charset=utf-8>
<title>Image cross effect with CSS3 transition</title>
<style type="text/css">
.changer img { transition: 1s ease-in-out; }
img.step1, div.changer:hover img.step2 { opacity: 1.0; }
.changer:hover img.step1, img.step2 { opacity: 0; }
</style>
</head>
<body>
<div class="changer">
<img class="step1" style="position: absolute;" src="https://www.w3resource.com/html-
css-exercise/pic1.png" alt="">
<img class="step2" src="https://www.w3resource.com/html-css-exercise/pic2.png"
alt="">
</div>
</body>
</html>
b. Google Font,
<html >
<head>
<title>Use Google Font exercise</title>
<link href='http://fonts.googleapis.com/css?family=Indie+Flower' rel='stylesheet'
type='text/css'>
<style type="text/css">
p{
font-family: 'Indie Flower', cursive;
}
</style>
</head>
<body>
<p>SQL tutorial of w3resource is a comprehensive tutorial to learn SQL. We have
followed SQL:2003 standard of ANSI. There are hundreds of examples given in this
tutorial. Output are shown with Oracle 10G. Often outputs are followed by pictorial
presentation and explanation for better understanding</p>
<script type="text/javascript">
WebFontConfig = {
google: { families: [ 'Indie+Flower::latin' ] }
};
(function() {
var wf = document.createElement('script');
wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
})();
</script>
</body>
</html>
Font Awesome Vector Icons with
Bootstrap3
<html>
<head>
<title> Use Font Awesome Vector Icons with Bootstrap 3</title>
<link rel="stylesheet"
href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<link href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css"
rel="stylesheet">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="btn-group open">
<a class="btn btn-primary" href="#"><i class="fa fa-user fa-fw"></i> User</a>
<a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">
<span class="fa fa-caret-down"></span></a>
<ul class="dropdown-menu">
<li><a href="#"><i class="fa fa-pencil fa-fw"></i> Edit</a></li>
<li><a href="#"><i class="fa fa-trash-o fa-fw"></i> Delete</a></li>
<li><a href="#"><i class="fa fa-ban fa-fw"></i> Ban</a></li>
<li class="divider"></li>
<li><a href="#"><i class="i"></i> Make admin</a></li>
</ul>
</div>
</div>
</div>
</div>
</body>
</html>
Calculating Values With CSS3 calc().
<html>
<head>
<title>HTML CSS Exercise - calculating values with CSS3</title>
<style type="text/css">
.container{
/* Calculate the width */
width: calc(500px - 10%);

background-color:#ec8007;
color:#fff;
text-align:center;
padding:10px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="container">
<p>CSS3 <em>calc</em> example</p>
</div>
</body>
</html>
Week 5
1. Write a JavaScript program to sum the multiples of 3 and 5 under 1000 ?
<html>
<head>
<title>week_5_1</title>
</head>
<body>
<script type="text/javascript">
var n=prompt("Enter the Uper limit" );
var sum=0;
var count=0;
for(i=1;i<n;i++)
{
if(i%3==0 || i%5==0)
{
count++;
document.write("\t"+i);
sum=sum+i;
}

}
document.write("</br></br>The total numbers multiples of 3 and 5 Under 1000 :"+count);
document.write("</br> the sum="+sum);
</script>
</body>
</html>

2. Write a JavaScript program to find the GCD of two numbers?


<html>
<head>
<title>week_5_2</title>
</head>
<body>
<script type="text/javascript">
var n1=prompt("Enter the First Number");
var n2=prompt("Enter the Secound Number");
var gcd;
var i;
for(i=1; i <= n1 && i <= n2; ++i)
{
// Checks if i is factor of both integers
if(n1%i==0 && n2%i==0)
gcd = i;
}

document.write(" The G.C.D of Two Numbers is :" +gcd);


</script>
</body>
</html>

3. Write a JavaScript function to test whether a string ends with a specified string

<html>

<head>

<title>JavaScript function to test whether a string ends with a specified string</title>

</head>

<body>

<script>

function endsWith(input, string) {

var index = input.length - string.length;

return index >= 0 && input.indexOf(string, index) > -1;

document.write(endsWith('JS string exercises', 'exercises'));


</script>

</body>

</html>

5. Write a program using Java Script that checks if two matrices have identical values in
all the elements.
<html>
<head>
<title>matrices_comparision</title>
</head>
<body>
<script type="text/javascript">
document.write("<h1> This Javascript is used to Check if two matrices are Equal</br>");
var mat1 =[
["One" ,"Two","Three"],
["Four" ,"Five" ,"Six"],
["Seven","Eight","Nine"]
];
var mat2 = [
['apple', 'orange', 'pear'],
['carrots', 'beans', 'peas'],
['cookies', 'cake', 'muffins',]
];
for (i=0; i <3; i++)
{
for (j=0; j <3; j++) {
if(mat1[i][j] !=mat2[i][j])
{
document.write("<h2> Matrices are not Equal</h2>")
break;
}
else{
document.write("<h3>Matrices are not Equal</h3></br>");
break;
}
}
}
</script>
</body>
</html>
6. Write a JavaScript program to check a credit card number and validate an email address?

<html>

<head>

<script type="text/javascript" src="jquery-3.3.1.js"></script>

<title>regexp</title>

<style type="text/css">

input{

border: solid blue;

padding: 20px;

width: 30%;

height: 10px;

color: blue;

font-family:"times new roman";

font-weight: bold;

border-radius: 20px;

margin-left: 200px;

button{

text-align: center;

padding: 20px;

width: 20%;

height: 20px;

color: blue;

font-family:"times new roman";

font-weight: bold;

border-radius: 20px;

margin-left: 200px;}
</style>

</head>

<body>

<input type="text" name="email" id="email" placeholder="Enter Your Email"></br>

<button id="btn" onclick="check_email()">Check Email</button>

<script type="text/javascript">

//this script is check email at client side using Regexp Object

function check_email()

var mail=document.getElementById("email").value;

// var email =new RegExp("^([a-z-+ \d \._A-Z]+)@([a-z\d-]+)(\.)([a-z]{2,6})$");

email= /^([a-z \m\d\._A-Z]+)@([a-z\d-]+)(\.)([a-z]{2,6})$/;

if(email.test(mail))

alert("Hello your email is Valid \n "+mail);

else

alert("Your Email is Invalid Sorry");

</script>

</body>

</html>

Week 6:
1.
a. Change button text using jQuery
<html>
<head>
<title>week_6_1</title>
<script src="jquery-3.3.1.js"></script>
</head>
<body>
<input style="color: blue;font-size: 22px;font-weight: bold;
margin-left: 400px" type="button" name="btn1" value="Click Me" id="btn1">
<script type="text/javascript">
$(document).ready(function(){
$('#btn1').click(function(){
$('#btn1').attr({value:"Wow Zahid we changed button"});
});
});
</script>
</body>
</html>

b. Set background-image using jQuery CSS property


<html>
<head>
<title>week_6_1</title>
<script src="jquery-3.3.1.js"></script>
</head>
<body id="body">
<h1> We are going to change background of Body</h1>
<input style="color: blue;margin-left: 400px" type="button" name="btn1" value="Click
Me to change background-image" id="btn1">
<script type="text/javascript">
$(document).ready(function(){
$('#btn1').click(function(){
$('body').css({
'background-image':'url("71.jpg")'
});
});
});
</script>
</body>
</html>

c. Remove a specific table row using jQuery.


<html>
<head>
<script src="jquery-3.3.1.js" type="text/javascript"></script>
<title>Remove_table_row</title>
<style>
table, th ,tr, button {
color: blue;
font-family: 'Times New Roman', 'Times, serif';
border: 1px solid black;
padding: 20px;
}
</style>
</head>
<body>
<table>
<thead>
<th>Name </th>
<th>Rollno</th>
</thead>
<tbody>
<tr>
<td>Muneer</td>
<td>100</td>
</tr>
<tr id="r2">
<td>Umar</td>
<td>105</td>
</tr>
</tr>
<td>Zahid</td>
<td>106</td>
</tr>
</tbody>
</table>
<button id="btn1">Click me to Delete Row Secound</button>
<script type="text/Javascript">
$(document).ready(function(){
$('#btn1').click(function(){
$('#r2').remove();
});
});</script>
</body>
</html>

d. Set value in input text using jQuery.


<html>
<head>
<script src="jquery-3.3.1.js" type="text/javascript"></script>
<title>change_text</title>
<style>
input,button {
font-size: 24px;
width: 90%;
color: blue;
font-family: 'Times New Roman', 'Times, serif';
border: 1px solid black;
padding: 20px;
}
</style>
</head><body>
<input type="text" name="txt" id="txt" ></br>
<button id="btn1">Click me to Add Text in Textbox</button>
<script type="text/Javascript">
$(document).ready(function(){
$('#btn1').click(function(){
$('#txt').attr({value:"Share your smile with the world. It's a symbol of friendship and
peace."});
});
});</script>
</body>
</html>

e. Set a value in a span using jQuery.


<html>
<head>
<style>
body{
font-size: 25px;
color: blue;
}</style>
<script src="jquery-3.3.1.js"></script>
<title>Set_span_text</title>
</head>
<body>
<p>The most important thing is to enjoy your life to be happy<span id="spn"
style="color:red">---Muneer</span></p>
<input id="btn1" type="button" value="Click to see the changes" />
<script type="text/javascript">
$(document).ready(function(){
$('#btn1').click(function(){
$("#spn").html(" its all that matters.");
});
});
</script>
</body>
</html

f. Find the class of the clicked element.


<html>
<head>
<script src="jquery-3.3.1.js"></script>
<title>Find_class.</title>
<style>
p, li{
font-size: 30px;
color: black;
margin-left: 40%;
}</style>
</head>
<body>
<p>Click on the color and get the class name.</p>
<ul class="tabs">
<li class="red">Red</li>
<li class="Black">Black</li>
<li class="Gold">Gold</li>
</ul>
</body>
<script type="text/javascript">
$("li").click(function() {
var colorClass = this.className;
alert("Class ="+colorClass);
});
</script>
</html>

g. Set href attribute at runtime using jQuery.


<html>
<head>
<script src="jquery-3.3.1.js"></script>
<title>change_url</title>
<style>
a{
font-size: 40px;
color: black;
margin-left: 40%;
}</style>
</head>
<body>
<a id="a1" href="http://www.google.com" >Google.com</a><br>
<button id="btn1" style="color:blue;font-size:22px">Click me to Change Link</button>
</body>
<script type="text/javascript">
$("#btn1").click(function() {
$("#a1").attr({href:'http://www.yahoo.com'});
$("#a1").html('Yahoo.com');
});
</script>
</html>

h. Remove disabled attribute using jQuery.


<html>
<head>
<script src="jquery-3.3.1.js"></script>
<title>change_url</title>
<style>
body {
font-size: 40px;
color: black;
margin-left: 40%;
}</style>
</head>
<body>
<input type="checkbox" id="disabledCheckboxes" disabled>Red
<input type="checkbox" id="disabledCheckboxes" disabled="disabled">Green
<p><input id="button1" type="button" value="Click to enable check boxes"/></p>
<script type="text/javascript">
$(document).ready(function(){
$('#button1').click(function(){
$('#disabledCheckboxes').prop("disabled", false);
alert(" Checkbox Enabled");
});
});
</script>
</body>
</html>
2. Write the jQuery code to Toggle a specified class when an element is clicked?
3. Write a jQuery Code to get a single element from a selection?
4. Using jQuery Display the tag's name on click?
5. Using jQuery Attach a function to the focus event. The focus event occurs (display a message
regarding the text field) when the <input> field gets focus?
6. Using jQuery Display the keyboard key which was pressed in a textbox?
7. Set background color of an element when the element (or any elements inside it) gets focus or
loses
focus.
Week 7
1. Create a simple HTML form and accept the user name and display the name through
PHP echo
statement

<?php
$name = $_POST['name'];
echo "<h3> Hello $name </h3>";
?>
<html>
<head>
<style>
body,input{
padding:15px;
color:black;
font-size:33px;
}
</style>
<title>access_html_form</title>
</head>
<body>
<form method='POST' action="week71.php">
<h2>Please input your name:</h2>
<input type="text" name="name" id="name"><br>
<input type="submit" value="Submit Name">
</form>
</body>
</html>

2. Write a PHP program to check the bits of the two given positions of a number are same
or not.
<?php
function test_bit_position($num, $pos1, $pos2) {
$pos1--;
$pos2--;
$bin_num = strrev(decbin($num));
if ($bin_num[$pos1] == $bin_num[$pos2]) {
return "true";
} else {
return "false";
}
}
echo test_bit_position(112,5,6)."\n";
?>

3. Write a PHP program to remove duplicates from a sorted list.


<?php
function remove_duplicates_list($list1) {
$nums_unique = array_values(array_unique($list1));
return $nums_unique ;
}
$nums = array(1,1,2,2,3,4,5,5);
print_r(remove_duplicates_list($nums));
?>

4. Write a PHP program to compute the sum of the prime numbers less than 100
<?php
primeno(100);
function primeno($n)
{
$sum=0;
for($i=1;$i<=$n;$i++){ //numbers to be checked as prime

$counter = 0;
for($j=1;$j<=$i;$j++){ //all divisible factors
if($i % $j==0){
$counter++;
}
}
//prime requires 2 rules ( divisible by 1 and divisible by itself)
if($counter==2){
print $i." is Prime <br/>";
$sum=$sum+$i;
}
}
echo ($sum);
}
?>

6. Write a PHP script to remove all white spaces in an array.


<?php
$my_array = array(15, null, " ", -2, NULL, "", " \n", "Red", 54, "\t");
print_r($my_array);
$result = array_filter($my_array, create_function('$x','return preg_match("#\S#", $x);'));
print_r($result);
?>
Week 8
1. Write a program to calculate and print the factorial of a number using a for loop.
<!DOCTYPE html>
<html>
<head>
<title>week_8_1</title>
</head>
<body>
<form method='post' action="week81.php">
<input type="number" name="num" placeholder="Enter Any Number">
<input type="submit" value="See Results">

</form>
<?php
$num= $_POST['num'];
//$num =5;
$fact= 1;
for($i=1;$i<=$num;$i++){
$fact=$fact*$i;
}
echo" The Factorial of Number $num =$fact </br>";
?>
</body>
</html>

2. Write a PHP script using nested for loop that creates a chess board?
<!DOCTYPE html>
<html>
<head>
<title>week_8_2</title>
<style>
body{
background-color :grey;
}
h3{
font-size:24px;
color:blue;
}
table{
border:10px solid yellow;
}
</style>
</head>
<body>
<center>
<h3>Chess Board using Nested For Loop</h3>

<table width="600px" cellspacing="2px" cellpadding="0px" ></Center>


<?php
for($row=1;$row<=8;$row++)
{
echo "<tr>";
for($col=1;$col<=8;$col++)
{
$total=$row+$col;
if($total%2==0)
{
echo "<td height=60px width=30px bgcolor=#FFFFFF></td>";
}
else
{
echo "<td height=60px width=30px bgcolor=#000000></td>";
}
}
echo "</tr>";
}
?>
</table>
</body>
</html>

4. Write a function to reverse a string.


<html>
<head>
<style>
body{
font-size:30px;
}
</style>
<title>reverse_string</title>
</head>
<body>
<?php
function Reverse($str){
echo"<h1> Orginal string is =$str<h1>";
return strrev($str);
}
$str = "my name is muneer";
$rev= Reverse($str);
echo"<h1> Reverse string is =$rev<h1>";
?>
</body>
</html>

5. Write a function to sort an array.


<?php
$myarry = array('m' =>"mango" ,'c' =>"Charry" ,'o' =>"orange" ,'a' =>"Apple ",'b' =>"Banana"
,'p1' =>"Pear" ,'p' =>"Pineapple" );
//$myarray = array("mango" ,"banana", "apple","pear");
$capitals = array("CA"=> "Sacramento", "TX"=> "Austin”,"OR"=> -[[[=-Salem");
ksort($myarry);
foreach( $myarry as $state => $city )
{
echo "$city, $state<br />";
}
?>

Week 9
1. Write a simple PHP class which displays an introductory message like "Hello All,
I am Scott", where "Scott" is an argument value of the method within the class.
<?php
class person
{
public $name,$n;
function set_name($new_name)
{
$str ="Hello All, I am ";
$this->name = $new_name;
$this->n=$str.$new_name;
}
function display(){
echo "</br>$this->n";
}
}
$p = new person();
$p->set_name("Scott");
$p->display();
?>

2. Write a PHP class that calculates the factorial of an integer.


<html>
<head><title>week_9_2</title>
<style>
.mystyle{
color:blue;
marigin-left;
background-color: yellow;
border-radius: 10px;
line-height:60px;
margin-left:300px;
text-align: center;
height: 60px;
width: 60%;
}
</style>
</head>
<body>
<?php
class factorial{
public $num;
function fact($n){
$fact=1;

for($i=1;$i<=$n;$i++)
{
$fact=$fact *$i;
}
echo"<h1 class='mystyle'> The Factorial of Number $n =$fact </h1></br>";
}
}
$f = new factorial();
$f->fact(9);
?>
</body></html>

3. Write a PHP class that sorts an ordered integer array with the help of sort()
function.
Sample array : array(11, -2, 4, 35, 0, 8, -9)
Output : Array ( [0] => -9 [1] => -2 [2] => 0 [3] => 4 [4] => 8 [5] => 11 [6] => 35 )
<!DOCTYPE html>
<html>
<head>
<title>week_9_3</title>
<style >body{font-size:40px;}</style>
</head>
<body>
<?php
class arraysort{
function display(){
$myarry= array(1,-2,4,35,0,8,9,55);
$len= count($myarry);
sort($myarry);
print_r($myarry);
}
}
$obj =new arraysort;
$obj->display();
?>
</body>
</html>
4. Calculate the difference between two dates using PHP OOP approach. Sample Dates :
1981-11-03,2013-09-04 Expected Result : Difference : 31 years, 10 months, 1 days

<?php

$sdate = new DateTime("1981-11-03");

$edate = new DateTime("2013-09-04");

$interval = $sdate->diff($edate);

echo "Difference : " . $interval->y . " years, " . $interval->m." months, ".$interval->d." days ";
?>

5. Write a PHP Calculator class which will accept two values as arguments, then add them,
subtract them,
multiply them together, or divide them on request. For example :
$mycalc = new MyCalculator( 12, 6);
echo $mycalc- > add(); // Displays 18
echo $mycalc- > multiply(); // Displays 72
<?php
class MyCalculator {

private $_fval, $_sval;

public function __construct( $fval, $sval ) {

$this->_fval = $fval;

$this->_sval = $sval;

public function add() {

return $this->_fval + $this->_sval;

public function subtract() {

return $this->_fval - $this->_sval;

public function multiply() {

return $this->_fval * $this->_sval;

public function divide() {

return $this->_fval / $this->_sval;

$mycalc = new MyCalculator(12, 6);


echo $mycalc-> add()."\n"; // Displays 18

echo $mycalc-> multiply()."\n"; // Displays 72

echo $mycalc-> subtract()."\n"; // Displays 6

echo $mycalc-> divide()."\n"; // Displays 2

?>

6. Write a PHP script to convert a string to Date and DateTime.


Sample Date : '12-08-2004' Expected Output : 2004-12-08
Note : PHP considers '/' to mean m/d/Y format and '-' to mean d-m-Y format.
<?php

$dt = DateTime::createFromFormat('m-d-Y', '12-08-2004')->format('Y-m-d');

echo $dt;

?>

Week 10

1. Write a PHP script to get time difference in days and years, months, days, hours, minutes,seconds

between two dates


<?php
$date1 = new DateTime('2012-06-01 02:12:51');

$date2 = $date1->diff(new DateTime('2014-05-12 11:10:00'));


echo $date2->days.'Total days'."\n";
echo $date2->y.' years'."\n";
echo $date2->m.' months'."\n";
echo $date2->d.' days'."\n";
echo $date2->h.' hours'."\n";
echo $date2->i.' minutes'."\n";
echo $date2->s.' seconds'."\n";
?>
2. Write a PHP script to change month number to month name.

<?php
$month_num = 7;
$month_name = date("F", mktime(0, 0, 0, $month_num, 10));
echo $month_name."\n";
?>
3. Write a PHP script to get yesterday's date.

<?php

$dt = new DateTime();


$dt->sub(new DateInterval('P1D'));
echo $dt->format('F j, Y')."\n";
?>
4. Write a PHP script to get the current date/time of 'Australia/Melbourne'.

<?php
date_default_timezone_set('America/Los_Angeles');
$date = date('m/d/Y h:i:s a', time());
echo $date;
?>
5. Write a PHP script to check if a date is a weekend or not.
<?php

$dt='2011-01-04';

$dt1 = strtotime($dt);

$dt2 = date("l", $dt1);

$dt3 = strtolower($dt2);

if(($dt3 == "saturday" )|| ($dt3 == "sunday"))

echo $dt3.' is weekend'."\n";

else

echo $dt3.' is not weekend'."\n";

}
?>

6. Write a PHP script to add/subtract the number of days from a particular date

Sample Output : Original date : 2011-01-01

Before 40 days : 2010-11-22

After 40 days : 2011-02-10

<?php

$dt='2011-01-01';

echo 'Original date : '.$dt."\n";

$no_days = 40;

$bdate = strtotime("-".$no_days." days", strtotime($dt));

$adate = strtotime("+".$no_days." days", strtotime($dt));

echo 'Before 40 days : '.date("Y-m-d", $bdate)."\n";

echo 'After 40 days : '.date("Y-m-d", $adate)."\n";

?>

8. Write a PHP function to get start and end date of a week (by week number) of a particular year

<?php

function Start_End_Date_of_a_week($week, $year)

$time = strtotime("1 January $year", time());

$day = date('w', $time);

$time += ((7*$week)+1-$day)*24*3600;

$dates[0] = date('Y-n-j', $time);

$time += 6*24*3600;

$dates[1] = date('Y-n-j', $time);

return $dates;

$result = Start_End_Date_of_a_week(12,2014);

echo 'Starting date of the week: '. $result[0]."\n";


echo 'End date the week: '. $result[1];

?>

1: Write a query to display the name (first_name, last_name) and salary for all employees whose
salary is not in the range $10,000 through $15,000.

SELECT first_name, last_name, salary


FROM employees
WHERE salary NOT BETWEEN 10000 AND 15000;

2: Write a query to display the name (first_name, last_name) and department ID of all
employees in departments 30 or 100 in ascending order.

SELECT first_name, last_name, department_id


FROM employees
WHERE department_id IN (30, 100)
ORDER BY department_id ASC;
3. Write a query to display the name (first_name, last_name) and salary for all employees whose
salary is not in the range $10,000 through $15,000 and are in department 30 or 100.
SELECT first_name, last_name, salary, department_id
FROM employees
WHERE salary NOT BETWEEN 10000 AND 15000
AND department_id IN (30, 100);
4. Write a query to display the name (first_name, last_name) and hire date for all
employees who were hired in 1987.
SELECT first_name, last_name, hire_date
FROM employees
WHERE YEAR(hire_date) LIKE '1987%';
5. Write a query to display the first_name of all employees who have both "b" and "c" in
their first name.
SELECT first_name
FROM employees
WHERE first_name LIKE '%b%'
AND first_name LIKE '%c%';
6.Write a query to display the last name, job, and salary for all employees whose job is
that of a Programmer or a Shipping Clerk, and whose salary is not equal to $4,500, $10,000, or
$15,000.
SELECT last_name, job_id, salary
FROM employees
WHERE job_id IN ('IT_PROG', 'SH_CLERK')
AND salary NOT IN (4500,10000, 15000);
7. Write a query to get the total salaries payable to employees.
SELECT SUM(salary)
FROM employees;
8. Write a query to get the minimum salary from employees table.
SELECT MIN(salary)
FROM employees;
9. Write a query to get the maximum salary of an employee working as a Programmer.
SELECT MAX(salary)
FROM employees
WHERE job_id = 'IT_PROG';
10. Write a query to get the average salary and number of employees working the
department 90.
SELECT AVG(salary),count(*)
FROM employees
WHERE department_id = 90;
11. Write a query to find the name (first_name, last_name) and hire date of the
employees who was hired after 'Jones'.
SELECT e.first_name, e.last_name, e.hire_date
FROM employees e
JOIN employees davies
ON (davies.last_name = 'Jones')
WHERE davies.hire_date < e.hire_date;
12. Write a query to get the department name and number of employees in the
department.
SELECT department_name AS 'Department Name',
COUNT(*) AS 'No of Employees'
FROM departments
INNER JOIN employees
ON employees.department_id = departments.department_id
GROUP BY departments.department_id, department_name
ORDER BY department_name;
13. Write a query to find the employee ID, job title, number of days between ending date
and starting date for all jobs in department 90.
SELECT employee_id, job_title, end_date-start_date Days FROM job_history
NATURAL JOIN jobs
WHERE department_id=90;
14. Write a query to display the department ID and name and first name of manager.
SELECT d.department_id, d.department_name, d.manager_id, e.first_name
FROM departments d
INNER JOIN employees e
ON (d.manager_id = e.employee_id);
15. Write a query to display the department name, manager name, and city.
SELECT d.department_name, e.first_name, l.city
FROM departments d
JOIN employees e
ON (d.manager_id = e.employee_id)
JOIN locations l USING (location_id);
16. Write a query to display the job title and average salary of employees.
SELECT job_title, AVG(salary)
FROM employees
NATURAL JOIN jobs
GROUP BY job_title;
17. Write a query to display job title, employee name, and the difference between salary
of the employee and minimum salary for the job.
SELECT job_title, first_name, salary-min_salary 'Salary - Min_Salary'
FROM employees
NATURAL JOIN jobs;
18. Write a query to get the DATE value from a given day (number in N)
SELECT FROM_DAYS(730677);
19. Write a query to get the firstname, lastname who joined in the month of June.
SELECT first_name, last_name
FROM employees WHERE MONTH(HIRE_DATE) = 6;
20. Write a query to get the years in which more than 10 employees joined.
SELECT DATE_FORMAT(HIRE_DATE,'%Y')
FROM employees
GROUP BY DATE_FORMAT(HIRE_DATE,'%Y')
HAVING COUNT(EMPLOYEE_ID) > 10;
21. Write a query to get first name of employees who joined in 1987.
SELECT FIRST_NAME, HIRE_DATE
FROM employees
WHERE YEAR(HIRE_DATE)=1987;
22. Write a query to get department name, manager name, and salary of the manager for
all managers whose experience is more than 5 years
SELECT DEPARTMENT_NAME, FIRST_NAME, SALARY
FROM departments D
JOIN employees E
ON (D.MANAGER_ID=E.MANAGER_ID)
WHERE (SYSDATE()-HIRE_DATE) / 365 > 5;
23. Write a query to get employee ID, last name, and date of first salary of the
employees.
SELECT employee_id, last_name, hire_date, LAST_DAY(hire_date)
FROM employees;
26. Write a query to update the portion of the phone_number in the employees table,
within the phone number the substring '124' will be replaced by '999'.
UPDATE employees
SET phone_number = REPLACE(phone_number, '124', '999')
WHERE phone_number LIKE '%124%';
27. Write a query to get the details of the employees where the length of the first name
greater than or equal to 8.
SELECT *
FROM employees
WHERE LENGTH(first_name) >= 8;
28. Write a query to display the first word from those job titles which contains more than
one words.
SELECT job_title, SUBSTR(job_title,1, INSTR(job_title, ' ')-1)
FROM jobs;
29. Write a query to display the first eight characters of the employees' first names and
indicates the amounts of their salaries with '$' sign. Each '$' sign signifies a thousand dollars. Sort
the data in descending order of salary.
SELECT left(first_name, 8),

REPEAT('$', FLOOR(salary/1000))
'SALARY($)', salary
FROM employees
ORDER BY salary DESC;
30. Write a query to display the employees with their code, first name, last name and hire
date who hired either on seventh day of any month or seventh month in any year.
SELECT employee_id,first_name,last_name,hire_date
FROM employees
WHERE POSITION("07" IN DATE_FORMAT(hire_date, '%d %m %Y'))>0;

You might also like