Ost Lab Manual r15
Ost Lab Manual r15
Ost Lab Manual r15
Experiment 01:
a) Performing basic DML, DDL commands using MySQL
Employee table
Dept table
Queries
List employee details.
SQL> select * from emp2b4;
Update emp2b4 table and change sal,comm. to 2000 & 500 respectively for an
employee with empno 7844.
SQL> update emp2b4 set sal=2000, comm=500 where empno=7844;
List all employee details whose empno=10 and whose job is clerk.
SQL> select * from emp2b4 where deptno=10 and job='CLERK';
Find minimum salary paid employee and employee details with that salaries.
SQL> select * from emp2b4 where sal=(select min(sal) from emp2b4);
Find the name of employee which starts with ‘A’ and end with ‘N’
SQL> select e.ename from emp2b4 e where e.ename like 'A%N';
List all employees who have a salary greater than 1500 in the order of department
number.
SQL> select * from emp2b4 where sal>1500 order by deptno;
Display all employee names, number, deptname & location of all employees.
SQL> select e.ename,e.empno,d.dname,d.loc from emp2b4 e,dept2b4 d where
d.deptno=e.deptno;
Find employee name employee number, their salary who were hired after 01/02/97.
SQL> select ename,empno,sal from emp2b4 where hiredate>'01-FEB-1997';
Experiment 02:
EMPLOYEE AND DEPARTMENT DATABASE
The BlueX Company Pvt. Ltd. has maintaining Employee information contains employee
details. The company has four departments. Any employee working in the company
belongs to any one of the department. An employee joined in company above 25 years
only. The company may give commission for every employee if and only if more than 2
years experience. Construct the database design with that there is no redundancy.
Answer to the following Queries:
i. List Employee Details.
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
17-Dec-
7369 SMITH CLERK 7902 80 800 20
20-Feb-
7499 ALLEN SALESMAN 7698 81 1600 300 30
22-Feb-
7521 WARD SALESMAN 7698 81 1250 500 30
02-Apr-
7566 JONES MANAGER 7839 81 2975 20
28-Sep-
7654 MARTIN SALESMAN 7698 81 1250 1400 30
7782 CLARK MANAGER 7839 09-Jun-81 2450 10
09-Dec-
7788 SCOTT ANALYST 7566 82 3000 20
17-Nov-
7839 KING PRESIDENT 81 5000 10
08-Sep-
7844 TURNER SALESMAN 7698 81 1500 0 30
7876 ADAMS CLERK 7788 12-Jan-83 1100 20
03-Dec-
7902 FORD ANALYST 7566 81 3000 20
7934 MILLER CLERK 7782 23-Jan-82 1300 10
iii. Update emp table and change employee name, ADAMS to ADAM.
update emp set ename='ADAM' where empno=7876;
iv. Update emp table and change sal, comm. To 2000 &500 to an employee no
7844.
update emp set sal=2000, comm=500 where empno=7844;
vi. List all employee details who belongs to deptno=10 and whose job is clerk.
select * from emp where deptno=10 and job='CLERK';
ix. List all employees who have a salary greater than 1500 in the order of
department number.
select * from emp where sal>1500 order by deptno;
x. Find minimum salary paid employee and employee details with that salaries?
select * from emp where sal=(select min(sal) from emp);
xi. Find the name of employee which starts with ‘A’ and end with ‘N’?
select e.ename from emp e where e.ename like 'A%N';
xii. List all employees who have a salary greater than 15000 in the order of
department number?
select * from emp where sal>1500 order by deptno;
xiv. Display all employee names, number, deptname & location of all employees?
select e.ename,e.empno,d.dname,d.loc from emp e,dept d where d.deptno=e.deptno;
xv. Find employee name employee number, their salary who were hired after
01/02/97
select ename,empno,sal from emp where hiredate>'01-FEB-1997';
PHP:
Experiment 03:
a) Write a PHP program to validate form contents using regular expressions.
Processing page
<?php
if($_POST)
{
$name = $_POST['name'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = $_POST['password'];
$gender = $_POST['gender'];
// Full Name
if (eregi('^[A-Za-z0-9 ]{3,20}$',$name))
{
$valid_name=$name;
}
else
{
$error_name='Enter valid Name.';
}
// Email
if (eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$', $email))
{
$valid_email=$email;
}
else
{
$error_email='Enter valid Email.';
}
// Gender
if ($gender==0)
{
$error_gender='Select Gender';
}
else
{
$valid_gender=$gender;
}
if((strlen($valid_name)>0)&&(strlen($valid_email)>0)
&&(strlen($valid_username)>0)&&(strlen($valid_password)>0) && $valid_gender>0 )
{
mysql_query(" SQL insert statement ");
header("Location: thanks.html");
}
else{ }
}
?>
Front page
<php include("validation.php"); ?>
<form method="post" action="" name="form">
Full name : <input type="text" name="name" value="<?php echo $valid_name; ?>" />
<?php echo $error_name; ?>
Email : <input type="text" name="name" value="<?php echo $valid_email; ?>" />
<?php echo $error_email; ?>
Username : <input type="text" name="name" value="<?php echo $valid_username; ?>"
/>
<?php echo $error_username; ?>
Password : <input type="password" name="name" value="<?php echo $valid_password;
?>" />
<?php echo $error_password; ?>
Gender : <select name="gender">
<option value="0">Gender</option>
<option value="1">Male</option>
<option value="2">Female</option>
</select>
<?php echo $error_gender; ?>
</form>
Experiment 03:
b) Write a PHP program to merge the contents of two files and store into another
file.
$lines = file('Country.txt');
$lines2 = file('countryenglish.txt');
Experiment 04:
a) Write a PHP program to create a ZIP file using PHP.
/* creates a compressed zip file */
function create_zip($files = array(),$destination = '',$overwrite = false) {
//if the zip file already exists and overwrite is false, return false
if(file_exists($destination) && !$overwrite) { return false; }
//vars
$valid_files = array();
//if files were passed in...
if(is_array($files)) {
//cycle through each file
foreach($files as $file) {
//make sure the file exists
if(file_exists($file)) {
$valid_files[] = $file;
}
}
}
//if we have good files...
if(count($valid_files)) {
//create the archive
$zip = new ZipArchive();
if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE :
ZIPARCHIVE::CREATE) !== true) {
return false;
}
//add the files
foreach($valid_files as $file) {
$zip->addFile($file,$file);
}
//debug
//echo 'The zip archive contains ',$zip->numFiles,' files with a status of
',$zip->status;
Experiment 04:
b) Write a PHP program to validate IP address, Integer and E-mail using filters.
IP address
<?php
$ip = "127.0.0.1";
// Validate e-mail
if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
echo("$email is a valid email address");
} else {
echo("$email is not a valid email address");
}
?>
Integer
<?php
$int = 100;
Experiment 05:
a) Write a PHP program to retrieve the data from MySQL database
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"].
"<br>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
Experiment 05:
b) Write a PHP program to implement sessions and cookies.
Creating a cookie
<?php
setcookie("user_name", "Guru99", time()+ 60,'/'); // expires after 60 seconds
echo 'the cookie has been set for 60 seconds';
?>
Retrieving a cookie
<?php
print_r($_COOKIE); //output the contents of the cookie array variable
?>
Deleting a cookie
<?php
setcookie("user_name", "Guru99", time() - 360,'/');
?>
Creating and accessing a session
<?php
if(isset($_SESSION['page_count']))
{
$_SESSION['page_count'] += 1;
}
else
{
$_SESSION['page_count'] = 1;
}
echo 'You are visitor number ' . $_SESSION['page_count'];
?>
Destroying a session
<?php
session_destroy(); //destroy entire session
?>
Experiment 06:
a) Write a PHP program to authenticate login credentials.
HTML page
<form name="frmUser" method="post" action="">
<div class="message"><?php if($message!="") { echo $message; } ?></div>
<table border="0" cellpadding="10" cellspacing="1" width="500"
align="center" class="tblLogin">
<tr class="tableheader">
<td align="center" colspan="2">Enter Login Details</td>
</tr>
<tr class="tablerow">
<td>
<input type="text" name="userName" placeholder="User Name"
class="login-input"></td>
</tr>
<tr class="tablerow">
<td>
<input type="password" name="password"
placeholder="Password" class="login-input"></td>
</tr>
<tr class="tableheader">
<td align="center" colspan="2"><input type="submit"
name="submit" value="Submit" class="btnSubmit"></td>
</tr>
</table>
</form>
PHP program
<?php
$message="";
if(count($_POST)>0) {
$conn = mysqli_connect("localhost","root","","phppot_examples");
$result = mysqli_query($conn,"SELECT * FROM users WHERE user_name='" .
$_POST["userName"] . "' and password = '". $_POST["password"]."'");
$count = mysqli_num_rows($result);
if($count==0) {
$message = "Invalid Username or Password!";
} else {
$message = "You are successfully authenticated!";
}
}
?
Experiment 06:
b) Write a PHP program to insert the contents of student registration form (Rno,
name, branch, age, email, and phone) into MySQL database.
<html>
<body>
<form action="2a.php" method="post">
NA:<input type="text" name="name"/></br>
S1:<input type="text" name="rno"/></br>
S2:<input type="text" name="branch"/></br>
S3:<input type="text" name="age"/></br>
S4:<input type="text" name="email"/></br>
S5:<input type="text" name="phone"/></br>
</br>
<input type="submit"/>
</form>
</body>
</html>
session_start();
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "mahi";
if(isset($_SESSION['val'])) {
$_SESSION["val"] = $_SESSION["val"]+1;
}
else
$_SESSION["val"] = 1;
echo($_SESSION["val"]);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$total=0;
$name=$_POST["name"];
$s1=$_POST["rno"];
$s2=$_POST["age"];
$s3=$_POST["branch"];
$s4=$_POST["email"];
$s5=$_POST["phone"];
mysqli_query($conn, $sql);
if ($_SESSION["val"]>=6) {
session_destroy();
header("Location: red.php");
}
else
{
header("Location: 2lab.html");
}
mysqli_close($conn);
?>
Experiment 06:
cursor: pointer;
}
.result p:hover{
background: #f2f2f2;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.search-box input[type="text"]').on("keyup input", function(){
/* Get input value on change */
var inputVal = $(this).val();
var resultDropdown = $(this).siblings(".result");
if(inputVal.length){
$.get("backend-search.php", {term: inputVal}).done(function(data){
// Display the returned data in browser
resultDropdown.html(data);
});
} else{
resultDropdown.empty();
}
});
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
if(isset($_REQUEST['term'])){
// Prepare a select statement
$sql = "SELECT * FROM countries WHERE name LIKE ?";
// Set parameters
$param_term = $_REQUEST['term'] . '%';
// Close statement
mysqli_stmt_close($stmt);
}
// close connection
mysqli_close($link);
?>
Experiment 07:
a) Write a PHP program to upload file into web server.
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been
uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
Experiment 07:
b) Write a PHP program to upload image into database.
Step 1 : Create a simple HTML form
<tbody><tr>
<td>
<input name="uploadedimage" type="file">
</td>
</tr>
<tr>
<td>
<input name="Upload Now" type="submit" value="Upload Image">
</td>
</tr>
</tbody></table>
</form>
To create a database table, we need to write a mysql query. If you want you can use
"phpmyadmin" an interface to create tables or database.
We will create a new php file for the connection and lets name it as "mysqlconnect.php". So lets
write mysql connection.
<!--?php
/**********MYSQL Settings****************/
$host="localhost";
$databasename="karma";
$user="root";
$pass="";
/**********MYSQL Settings****************/
$conn=mysql_connect($host,$user,$pass);
if($conn)
{
$db_selected = mysql_select_db($databasename, $conn);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
}
else
{
die('Not connected : ' . mysql_error());
}
?-->
To store uploaded image path in database we will create a new php file name it as
"saveimage.php" because in the "form" tag we gave "action" attribute target path as
"saveimage.php" and in this file ("saveimage.php") all the form-data will be posted.
First lets include the mysql connection file in top of "saveimage.php" file.
<?php
include("mysqlconnect.php");
?>
Second let' write a simple function which will give us the image extension from a image
type because there are different image types available to upload like"jpeg, gif, png,
bmp" etc. So we have to create a simple function which will return us the image
extension depending on the image-type.
view source
print
?
?php
function GetImageExtension($imagetype)
{
if(empty($imagetype)) return false;
switch($imagetype)
{
case 'image/bmp': return '.bmp';
case 'image/gif': return '.gif';
case 'image/jpeg': return '.jpg';
case 'image/png': return '.png';
default: return false;
}
}
?
If you want to save an image with new name then only use the above function other
wise you can also get uploaded image name with extension by using the global PHP
$_FILES["uploadedimage"]["name"] variable.
In this example we will be storing an image with new name so we will be using that
above "GetImageExtension()" function.
Let's store an Image in database with new name
<?php
include("mysqlconnect.php");
function GetImageExtension($imagetype)
{
if(empty($imagetype)) return false;
switch($imagetype)
{
case 'image/bmp': return '.bmp';
case 'image/gif': return '.gif';
case 'image/jpeg': return '.jpg';
case 'image/png': return '.png';
default: return false;
} }
if (!empty($_FILES["uploadedimage"]["name"])) {
$file_name=$_FILES["uploadedimage"]["name"];
$temp_name=$_FILES["uploadedimage"]["tmp_name"];
$imgtype=$_FILES["uploadedimage"]["type"];
$ext= GetImageExtension($imgtype);
$imagename=date("d-m-Y")."-".time().$ext;
$target_path = "images/".$imagename;
if(move_uploaded_file($temp_name, $target_path)) {
$query_upload="INSERT into 'images_tbl' ('images_path','submission_date')
VALUES
('".$target_path."','".date("Y-m-d")."')";
}else{
exit("Error While uploading image on the server");
}
}
?>
<?php
include("mysqlconnect.php");
$select_query = "SELECT 'images_path' FROM 'images_tbl' ORDER by 'images_id' DESC";
$sql = mysql_query($select_query) or die(mysql_error());
while($row = mysql_fetch_array($sql,MYSQL_BOTH)){
?>
<table style="border-collapse: collapse; font: 12px Tahoma;" cellspacing="5" cellpadding="5"
border="1">
<tbody><tr>
<td>
<imgsrc="<?php echo $row[" images_path"];="" ?="">" alt="" />">
</td>
</tr>
</tbody></table>
<php
}? >
PYTHON :
Experiment 08:
a) Write a Program to print the Fibonacci sequence using python
# Program to display the Fibonacci sequence up to n-th term where n is provided by the
user
Experiment 08:
b) Write a Program to display the Armstrong numbers between the specified
ranges.
# Program to check Armstrong numbers in certain interval
lower = 100
upper = 2000
# order of number
order = len(str(num))
# initialize sum
sum = 0
if num == sum:
print(num)
Experiment 08:
c) Write a Program to perform various operations on Tuples and Dictionaries.
my_tuple = ('p','e','r','m','i','t')
# Output: 'p'
print(my_tuple[0])
# Output: 't'
print(my_tuple[5])
#print(my_tuple[6])
#my_tuple[2.0]
# nested tuple
n_tuple = ("mouse", [8, 4, 6], (1, 2, 3))
# nested index
# Output: 's'
print(n_tuple[0][3])
# nested index
# Output: 4
print(n_tuple[1][1])
# create a dictionary
squares = {1:1, 2:4, 3:9, 4:16, 5:25}
# Output: {2: 4, 3: 9}
print(squares)
# Output: {}
print(squares)
# Throws Error
# print(squares)
Experiment 08:
# 3x3 matrix
X = [[12,7,3],
[4 ,5,6],
[7 ,8,9]]
# 3x4 matrix
Y = [[5,8,1,2],
[6,7,3,0],
[4,5,9,1]]
# result is 3x4
result = [[0,0,0,0],
[0,0,0,0],
[0,0,0,0]]
for r in result:
print(r)
Experiment 09:
a. Write a Program to make a simple calculator using python
# This function adds two numbers
def add(x, y):
return x + y
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
if choice == '1':
print(num1,"+",num2,"=", add(num1,num2))
Experiment 09:
b. Write a program to find maximum element in the list using recursive functions.
def Max(list):
if len(list) == 1:
return list[0]
else:
m = Max(list[1:])
return m if m > list[0] else list[0]
def main():
list = eval(raw_input(" please enter a list of numbers: "))
print("the largest number is: ", Max(list))
main()
Experiment 09:
c. Write a program to find GCD and LCM of two numbers using functions.
x,y = input("Enter two integer").split()
x,y = [int(x), int(y)] #convert input string to integers
a=x
b=y
while(b != 0 ):
t=b
b=a%b
a=t
hcf = a
lcm = (x*y)/hcf
Experiment 10:
a. Write a Program to recursively calculate the sum of natural numbers using
python
# Python program to find the sum of natural numbers up to n using recursive function
defrecur_sum(n):
"""Function to return the sum
of natural numbers using recursion"""
if n <= 1:
return n
else:
return n + recur_sum(n-1)
if num< 0:
print("Enter a positive number")
else:
print("The sum is",recur_sum(num))
Experiment 10:
b. Write a Program to sort words in alphabetic order using python.
# Program to sort alphabetically the words form a string provided by the user
Experiment 10:
c. Write a program to copy the contents from one file to another file.
with open("test.txt") as f:
with open("out.txt", "w") as f1:
for line in f:
f1.write(line)
#or go with next program to read and write seperately
#Read from a file #Write to a file
f = open("./read_file.py", "r");
print f f = open("./new.txt", "a");
for line in f.readlines(): value = ('My name is', "Sergio")
print line myString = str(value)
f.write(myString)
f.close()
Experiment 11:
a. Write a Program to handle Exceptions using python
#exception program 1
#!/usr/bin/python
try:
fh = open("testfile", "r")
fh.write("This is my test file for exception handling!!")
except IOError:
print "Error: can\'t find file or read data"
else:
print "Written content in the file successfully"
class ValueTooSmallError(Error):
"""Raised when the input value is too small"""
pass
class ValueTooLargeError(Error):
"""Raised when the input value is too large"""
pass
while True:
try:
i_num = int(input("Enter a number: "))
if i_num< number:
raise ValueTooSmallError
elifi_num> number:
raise ValueTooLargeError
break
except ValueTooSmallError:
print("This value is too small, try again!")
print()
except ValueTooLargeError:
print("This value is too large, try again!")
print()
Experiment 11:
b. Write a Program to display Powers of 2 Using Anonymous Function using
python
Experiment 12:
defsel():
selection = "You selected the option " + str(var.get())
label.config(text = selection)
root = Tk()
var = IntVar()
R1 = Radiobutton(root, text="Option 1", variable=var, value=1,command=sel)
R1.pack( anchor = W )
label = Label(root)
label.pack()
root.mainloop()
#program to get a textbox and reset text typed
from tkinter import *
defbuttonPushed():
#print("button pushed")
txt=t.get()
print("text in the box is",txt)
defresetPushed():
t.delete(1,END)
root = Tk()
t = Entry()
t.pack()
root.mainloop()
Experiment 12:
b. Write a program to access MySQL DB using Python.
cursor.execute(sql)
# Inserting in Table Example:- Prepare SQL query to INSERT a record into the database
and accept the value dynamic. This is similar to prepare statement which we create.
sql = “INSERT INTO SIDDHU_TEST(FNAME, \
LNAME) \
VALUES (‘%s’, ‘%s’)” % \
(‘siddhu’, ‘dhumale’)
try:
# Execute command
cursor.execute(sql)
# Commit changes
db.commit()
except:
# Rollback if needed
db.rollback()
# disconnect from server
db.close()
print(“Data Inserted properly “+a +”–“+b)
elif selection in (‘Update’):
# Open database connection
db = MySQLdb.connect(“localhost”,”siddhu”,”siddhu”,”siddhutest” )
# prepare a cursor object using cursor() method
cursor = db.cursor()
# execute SQL query
cursor.execute(“SELECT VERSION()”)
# Fetch a single row
data = cursor.fetchone()
print (“Database version : %s ” % data)
# Update Exmaple:- Update record
sql = “UPDATE SIDDHU_TEST SET LNAME = ‘%s'” % (b) +” WHERE FNAME = ‘%s'” % (a)
try:
# Execute the SQL command
cursor.execute(sql)
# Commit your changes in the database
db.commit()
except:
# Rollback in case there is any error
db.rollback()
db.close()
print(“Data Updated properly “+a +”–“+b)
elif selection in (‘Delete’):
# Open database connection
db = MySQLdb.connect(“localhost”,”siddhu”,”siddhu”,”siddhutest” )
# prepare a cursor object using cursor() method
cursor = db.cursor()
Output:
Experiment 13:
a. Write a JQuery Script to implement hide() and show() effects
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#hide").click(function(){
$("p").hide();
});
$("#show").click(function(){
$("p").show();
});
});
</script>
</head>
<body>
<button id="hide">Hide</button>
<button id="show">Show</button>
</body>
</html>
Output:-
Clicking on hide will hide text above button and clicking on show will show the text
Experiment 13:
b. Write a JQuery Script to apply various sliding effects
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#flip").click(function(){
$("#panel").slideToggle("slow");
});
});
</script>
<style>
#panel, #flip {
padding: 5px;
text-align: center;
background-color: #e5eecc;
border: solid 1px #c3c3c3;
}
#panel {
padding: 50px;
display: none;
}
</style>
</head>
<body>
</body>
</html>
Output:-
Experiment 14:
a. Write a JQuery script to animate the given image when ever user clicks on a
button.
<html>
<head>
<title>The jQuery Example</title>
<script type = "text/javascript"
src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<style>
.clickme{
margin:10px;
padding:12px;
border:2px solid #666;
width:100px;
height:50px;
}
</style>
</head>
<body>
<div class = "content">
<div class = "clickme">Click Me</div>
<div class = "target">
<imgsrc = "./images/jquery.jpg" alt = "jQuery" />
</div>
<div class = "log"></div>
</div>
</body>
</html>
Output:-
Output before animate
After animate
Experiment 14:
b. Write a JQuery script to apply various CSS effects
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").css({"background-color": "yellow", "font-size": "200%"});
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
</body>
</html>
Output:-
After clicking on button we apply same style to all para by css method
Experiment 15:
a. Write a program to apply various filters to transform data.
<!DOCTYPE html>
<html>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<ul>
<li ng-repeat="x in names | filter:test">
{{ x }}
</li>
</ul>
</div>
<script>
angular.module('myApp', []).controller('namesCtrl', function($scope) {
$scope.names = [
'Jani',
'Carl',
'Margareth',
'Hege',
'Joe',
'Gustav',
'Birgit',
'Mary',
'Kai'
];
});
</script>
</body>
</html>
Output:-
Initially before applying filter
Experiment 15:
b. Write a program to display data in tables in various forms
<html>
<head>
<title>Angular JS Table</title>
<script src =
"https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<style>
table, th , td {
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd) {
background-color: #f2f2f2;
table tr:nth-child(even) {
background-color: #ffffff;
}
</style>
</head>
<body>
<h2>AngularJS Sample Application</h2>
<div ng-app = "mainApp" ng-controller = "studentController">
<tr>
<td>Enter last name: </td>
<td>
<input type = "text" ng-model = "student.lastName">
</td>
</tr>
<tr>
<td>Name: </td>
<td>{{student.fullName()}}</td>
</tr>
<tr>
<td>Subject:</td>
<td>
<table>
<tr>
<th>Name</th>.
<th>Marks</th>
</tr>
</table>
</td>
</tr>
</table>
</div>
<script>
varmainApp = angular.module("mainApp", []);
mainApp.controller('studentController', function($scope) {
$scope.student = {
firstName: "Mahesh",
lastName: "Parashar",
fees:500,
subjects:[
{name:'Physics',marks:70},
{name:'Chemistry',marks:80},
{name:'Math',marks:65},
{name:'English',marks:75},
{name:'Hindi',marks:67}
],
fullName: function() {
varstudentObject;
studentObject = $scope.student;
return studentObject.firstName + " " + studentObject.lastName;
}
};
});
</script>
</body>
</html>
Output:-
Experiment 15:
c. Write a program to apply animations
<!DOCTYPE html>
<html>
<style>
div {
transition: all linear 0.5s;
background-color: lightblue;
height: 100px;
width: 100%;
position: relative;
top: 0;
left: 0;
}
.ng-hide {
height: 0;
width: 0;
background-color: transparent;
top:-200px;
left: 200px;
}
</style>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-
animate.js"></script>
<body ng-app="myApp">
<div ng-hide="myCheck"></div>
<script>
var app = angular.module('myApp', ['ngAnimate']);
</script>
</body>
</html>
Output:-
Additional Programs
<?php
//insert query
$link = mysqli_connect('localhost', 'root', 'root', 'srikanth');
/* check connection */
if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
else
echo "connected successfully";
$sno = 50;
$name = "naveesdfn";
$num = 30;
$sal = 49000;
mysqli_stmt_execute($stmt);
mysqli_close($link);
?>
<?php
$link = mysqli_connect('localhost', 'root', 'root', 'srikanth');
/* check connection */
if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
else
echo "connected successfully<br>";
$sal=35000;
mysqli_stmt_execute($stmt);
echomysqli_field_count ($link)."<br>";
while (mysqli_stmt_fetch($stmt)) {
printf ("%d %s %d %d\n<br>", $sno, $name, $salary, $deptno);
}
mysqli_stmt_close($stmt);
mysqli_close($link);
?>
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "srikanth";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
else
echo "Connected successfully<br>";
?>
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "srikanth";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
else
echo "Connected successfully<br>";
?>
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "srikanth";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
else
echo "Connected successfully<br>";
// now as the db connection is done we may perform the required db operation
if ($result!=FALSE) {
//fetch row takes mysqli_result as parameter , fetches one row of
data from result set it as an enumerated array, where each column is stored in an array
offset starting from 0 (zero)
while ($row = mysqli_fetch_row($result)) {
printf("%s %s<br>", $row[0], $row[1]);
}
mysqli_free_result($result);
}
printf("<br>-----------------<br>");
/*
Returns TRUE if one or more result sets are available from a previous call
to mysqli_multi_query(), otherwise FALSE
*/
/*
/* close connection */
mysqli_close($conn);
?>