SlideShare uma empresa Scribd logo
1 de 40
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 1
1. Write a JavaScript to design a simple calculator to perform the
following operations: sum, product, difference and quotient.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Simple Calculator</title>
<script type="text/javascript">
var op1= 0,op2= 0,operator="",res="",from="";
function reset()
{
document.getElementById('res').value = "";
op1=0;op2=0;operator="";res="";from="";
}
function insertOperand(operand)
{
if(from == "calculate")
reset();
else if(from == "operator")
document.getElementById('res').value = "";
document.getElementById('res').value+=ope
rand; from = "operand";
}
function insertOperator(op)
{
if(op1 == 0)
{
op1=document.getElementById('res').value;
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 2
}
else
{
if(from == "operand")
{
calculate();
}
}
operator=op;
from="operator";
}
function calculate()
{
op2=document.getElementById('res').value;
op1=parseInt(op1);
op2=parseInt(op2);
switch (operator)
{
case '+':res=op1+op2;
break;
case '-' :res=op1-op2;
break;
case '*':res=op1*op2;
break;
case '/':
if(op2 == 0)
res=0;
else
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 3
res=parseInt(op1/op2);
break;
}
document.getElementById('res').value=
res; op1=res;
op2=0;
operator="";
from="calculate";
}
</script>
<style type="text/css">
input {width: 100%}
h1 {text-align: center}
</style>
</head>
<body onload="reset()">
<h1>Simple Calculator</h1>
<table align="center" border="1">
<tr>
<td colspan="5"><input type="text" id="res" name="res" value=""
/></td>
</tr>
<tr>
<td><input type="button" value="7"
onclick="insertOperand('7')"/></td>
<td><input type="button" value="8" onclick="insertOperand('8')"
/></td>
<td><input type="button" value="9" onclick="insertOperand('9')"
/></td>
<td><input type="button" value="+" onclick="insertOperator('+')"
/></td>
<td><input type="button" value="-" onclick="insertOperator('-')"
/></td>
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 4
</tr>
<tr>
<td><input type="button" value="4" onclick="insertOperand('4')"
/></td> <td><input type="button" value="5"
onclick="insertOperand('5')" /></td> <td><input type="button"
value="6" onclick="insertOperand('6')" /></td> <td><input
type="button" value="*" onclick="insertOperator('*')" /></td>
<td><input type="button" value="/"
onclick="insertOperator('/')"/></td> </tr>
<tr>
<td><input type="button" value="1" onclick="insertOperand('1')" /></td>
<td><input type="button" value="2" onclick="insertOperand('2')" /></td>
<td><input type="button" value="3" onclick="insertOperand('3')" /></td>
<td><input type="button" value="0" onclick="insertOperand('0')" /></td>
<td><input type="button" value="=" onclick="calculate()" /></td>
.
</tr>
<tr>
<td colspan="5"><input type="button" size="100%" value="CLEAR"
onclick="reset()" /> </td>
</tr>
</table>
</body>
</html>
OUTPUT:
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 5
2. Write a JavaScript that calculates the squares and cubes of the
numbers from 0 to 10 and outputs HTML text that displays the resulting
values in an HTML table format.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Program for Squares and
Cubes</title> <style type="text/css">
table,h1 {text-align: center}
</style>
</head>
<body>
<h1>Program to find Square and Cube</h1>
<script type="text/javascript">
var mytable="<table border='1' align='center'> <tr>
<th>Number</th> <th>Square</th> <th>Cube</th>
</tr>";
var square= 0,cube=0;
for(var i=0;i<=10;i++)
{
square=i*i;
cube=i*i*i;
mytable+="<tr><td>"+i+"</td><td>"+square+"</td>
<td>"+cube+"</td></tr>"
}
mytable+="</table>";
document.write(mytable);
</script>
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 6
</body>
</html>
Output :
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 7
3. Write a JavaScript code that displays text “TEXT-GROWING” with
increasing font size in the interval of 100ms in RED COLOR, when the
font size reaches 50pt it displays “TEXT-SHRINKING” in BLUE color.
Then the font size decreases to 5pt.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Prog for Text Animation</title>
<script type="text/javascript">
function animate()
{
var
val=window.getComputedStyle(document.getElementById('text')
).fontSize; var fontsize=parseInt(val);
var state="growing";
var timer=setInterval(textanimate,100);
function textanimate()
{
if(state=="growing")
{
fontsize++;
document.getElementById('text').innerHTML="TEXT GROWING";
document.getElementById('text').style.color="red";
document.getElementById('text').style.fontSize=fontsize+
"pt";
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 8
}
if(state=="shrinking")
{
fontsize--;
document.getElementById('text').innerHTML="TEXT SHRINKING";
document.getElementById('text').style.color="blue";
document.getElementById('text').style.fontSize=fontsize+
"pt";
}
if(fontsize==50)
{
state="shrinking"
}
if(fontsize==5)
{
clearInterval(timer);
}
}
}
</script>
</head>
<body onload="animate()">
<h1 style="text-align: center">
Program for Increasing / Decreasing size of a
text </h1>
<p style="text-align: center;"
id="text"></p> </body>
</html>
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 9
OUTPUT:
(a) Animation for text growing
(b) Animation for text shrinking
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 10
4. Develop and demonstrate a HTML5 file that includes JavaScript
script that uses functions for the following problems:
a. Parameter: A string
b. Output: The position in the string of the left-most vowel
c. Parameter: A number
d. Output: The number with its digits in the reverse order
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Program to find leftmost vowel and digits in reverse
order</title> <script type="text/javascript">
function validate()
{
var inp=document.getElementById('val').value;
if(isNaN(inp))
findVowel(inp);
else
findReverse(inp);
}
function findVowel(inp)
{
var str=inp.toLowerCase();
var pos=0,ch="";
for(var i=0;i<str.length;i++)
{
ch=str.charAt(i);
if(ch=="a"||ch=="e"||ch=="i"||ch=="o"||ch=="u")
{
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 11
pos=i+1;
break;
}
}
if(pos==0)
alert("Vowel not found");
else
alert("Position of Left Most Vowel in the string :
"+pos);
}
function findReverse(inp)
{
var num=parseInt(inp);
var temp=num;
var rem= 0,rev= 0;
while(num>0)
{
rem=num%10;
rev=rev*10+rem;
num=parseInt(num/10);
}
alert("Number : "+temp+"nReverse Order : "+rev);
}
</script>
</head>
<body
>
<h1>
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 12
Program to find left most vowel or Digits in reverse order
</h1>
<input type="text" name="val" id="val" placeholder="Enter String or
Digits"> <input type="button" value="submit" onclick="validate()">
</body>
</html>
Output :
(a) When you enter the string as input
(b) When you enter the digits as input
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 13
5. Design an XML document to store information about a student in an
engineering college affiliated to VTU. The information must include
USN, Name, and Name of the College, Branch, Year of Joining, and email
id. Make up sample data for 3 students. Create a CSS style sheet and
use it to display the document.
5.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css"
href="5.css"?> <!DOCTYPE student [
<!ELEMENT student_info (h1,h2+,ad+)>
<!ELEMENT ad (label)>
<!ELEMENT usn (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT col (#PCDATA)>
<!ELEMENT branch (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT email (#PCDATA)>
<!ELEMENT label (#PCDATA|usn|name|col|branch|year|email)*>
<!ELEMENT h2 (#PCDATA)>
<!ELEMENT h1 (#PCDATA)>]>
<student_info>
<h1>Student information</h1>
<h2>Student1</h2>
<ad><label>USN:<usn>4ES15CS001</usn></label></ad>
<ad><label>NAME:<name>AAA</name></label></ad>
<ad><label>COLLEGE:<col>SSE, MUKKA</col></label></ad>
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 14
<ad><label>BRANCH:<branch>CSE</branch></label></ad>
<ad><label>YEAR:<year>2011</year></label></ad>
<ad><label>EMAIL:<email>abc@gmail.com</email></label></ad>
<h2>Student2</h2>
<ad><label>USN:<usn>4ES15IS002</usn></label></ad>
<ad><label>NAME:<name>BBB</name></label></ad>
<ad><label>COLLEGE:<col>SSE, MUKKA</col></label></ad>
<ad><label>BRANCH:<branch>ISE</branch></label></ad>
<ad><label>YEAR:<year>2012</year></label></ad>
<ad><label>EMAIL:<email>efg@gmail.com</email></label></ad>
<h2>Student3</h2>
<ad><label>USN:<usn>4ES15CS003</usn></label></ad>
<ad><label>NAME:<name>CCC</name></label></ad>
<ad><label>COLLEGE:<col>SSE, MUKKA</col></label></ad>
<ad><label>BRANCH:<branch>CSE</branch></label></ad>
<ad><label>YEAR:<year>2013</year></label></ad>
<ad><label>EMAIL:<email>hij@gmail.com</email></label></ad>
</student_info>
5.css
h1 {color:green;font-size:50px;}
h2 {display:block;margin-left:40px;color:brown;font-size:40px;}
ad {display:block;margin-left:80px;margin-
top:20px;color:blue;font-size:20px;}
usn {color:red;margin-left:20px;font-size:20px;} name
{color:red;margin-left:20px;font-size:20px;} col
{color:red;margin-left:20px;font-size:20px;} branch
{color:red;margin-left:20px;font-size:20px;} year
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 15
{color:red;margin-left:20px;font-size:20px;} email
{color:red;margin-left:20px;font-size:20px;}
Output :
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 16
6.Write a PHP program to keep track of the number of visitors
visiting the web page and to display this count of visitors, with
proper headings.
index.php
<html>
<head>
<title>Visitors Count</title>
<style type="text/css">
h1,h2 {text-align: center}
</style>
</head>
<body>
<h1>Welcome to MY WEB PAGE</h1>
<?php
$file="count.txt";
$handle=fopen($file,'r') or die("Cannot Open File : $file");
$count=fread($handle,10);
fclose($handle);
$count++;
echo "<h2>No of visitors who visited this page : $count </h2>";
$handle=fopen($file,'w') or die("Cannot Open File : $file");
fwrite($handle,$count);
fclose($handle);
?>
</body>
</html>
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 17
Instruction :
Create an empty file named count.txt in the same folder before
executing.
Output :
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 18
7. Write a PHP program to display a digital clock which displays the
current time of the server.
index.php
<html>
<head>
<meta http-equiv="refresh" content="1">
<title>Digital Clock</title>
<style type="text/css">
h1 {text-align: center}
</style>
</head>
<body>
<?php
echo "<h1>Digital Clock</h1>";
echo "<hr/>";
echo "<h1>".date('h:i:s A')."</h1>";
echo "<hr/>";
?>
</body>
</html>
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 19
Output :
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 20
8. Write the PHP programs to do the following:
a. Implement simple calculator operations.
b. Find the transpose of a matrix.
c. Multiplication of two matrices.
d. Addition of two matrices.
8a.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Simple Calculator</title>
</head>
<body>
<form action="8a.php" method="post">
<h1>Simple Calculator</h1>
<p>First Operand: <input type="text" name="op1"
/></p> <p>Choose Operator:
<input type="radio" name="operator" checked="checked" value="+" />
Add(+)
<input type="radio" name="operator" value="-" /> Subtract(-)
<input type="radio" name="operator" value="*" /> Multiply(*)
<input type="radio" name="operator" value="/" /> Divide(/)
</p>
<p>Second Operand: <input type="text" name="op2"></p>
<p><input type="submit" name="submit" value="Submit">
<input type="reset" name="submit"
value="Reset"></p> </form>
</body>
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 21
</html>
8a.php
<html>
<head>
<title>Result Page</title>
<style type="text/css">
h1,h2 {text-align: center}
</style>
</head>
<body>
<?php
$op1=$_POST['op1'];
$op2=$_POST['op2'];
$operator=$_POST['operator'];
switch($operator)
{
case '+':$res=$op1+$op2;
break;
case '-':$res=$op1-$op2;
break;
case '*':$res=$op1*$op2;
break;
case '/':if($op2==0)
$res=0;
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 22
else
$res=$op1/$op2;
break;
}
echo "<h1>Simple Calculator</h1>";
echo
"<h2>".$op1.$operator.$op2."=".$res."</h2>";
?>
</body>
Output :
(a) HTML input page
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 23
(b) PHP output/result page
8b.php
<?php
$mat=Array(Array(1,2),
Array(4,5),
Array(7,8)); //Initializing Array in PHP
$transpose=Array(); //Creating empty array in PHP
echo "<html><head><title>Matrix Transpose</title></head><body>";
echo "<h1>Matrix is:<br/>";
for($i = 0; $i < count($mat); $i++)
{
for ($j = 0; $j < count($mat[0]); $j++)
{
echo $mat[$i][$j] . " ";
}
echo "</br/>";
}
echo "</h1>";
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 24
for($i = 0; $i < count($mat); $i++)
//calculation for
Transpose
for($j = 0; $j < count($mat[0]);
$j++)
{
$transpose[$j][$i]=$mat[$i][$j
];
}
echo "<h1>Transpose of a Matrix
is:<br/>";
for($i = 0; $i < count($transpose);
$i++)
{
for ($j = 0; $j < count($transpose[0]); $j++)
{
echo $transpose[$i][$j] . " ";
}
echo "<br/>";
}
echo "</h1>";
echo "</body></html>";
?>
Output :
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 25
8c.php
<?php
$ mat1=Array(Array(1,2),
Array(3,4),
Array(5,6) );
$mat2=Array(Array(2,4,8),
Array(1,3,5) );
echo "<html><head><title>Matrix Multiplication</title></head><body>";
if(count($mat1[0])!=count($mat2))
{
//column(1st matrix) != row(2nd matrix)
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 26
echo "<h1>Incompatible Matrices</h1>";
exit(0);
}
$res=array();
echo "<h1>Matrix A:<br/>";
for($i = 0; $i < count($mat1); $i++)
{
for ($j = 0; $j < count($mat1[0]); $j++)
{
echo $mat1[$i][$j] . " ";
}
echo "<br/>";
}
echo "</h1>";
echo "<h1>Matrix B:<br/>";
for($i = 0; $i < count($mat2); $i++)
{
for ($j = 0; $j < count($mat2[0]); $j++)
{
echo $mat2[$i][$j] . " ";
}
echo "<br/>";
}
echo "</h1>";
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 27
for($i = 0; $i < count($mat1); $i++)
for($j = 0; $j < count($mat2[0]); $j++)
{
$res[$i][$j]=0;
for($k=0;$k<count($mat2);$k++)
$res[$i][$j]=$res[$i][$j]+$mat1[$i][$k]*$mat2[$k][$j];
}
echo "<h1>A x B:<br/>";
for($i = 0; $i < count($res); $i++)
{
for ($j = 0; $j < count($res); $j++)
{
echo $res[$i][$j] . " ";
}
echo "<br/>";
}
echo "</h1>";
echo "</body></html>";
Output :
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 28
8d.php
<?php
$mat1=Array(Array(1,2),
Array(3,4),
Array(5,6));
$mat2=Array(Array(1,1),
Array(2,2),
Array(3,3));
echo "<html><head><title>Matrix Addition</title></head><body>";
if((count($mat1)!=count($mat2))||(count($mat1[0])!=count($mat2[0]))) {
echo "<h1>Incompatible Matrices</h1>";
exit(0);
}
echo "<h1>Matrix A:<br/>";
for($i=0;$i<count($mat1);$i++)
{
for ($j = 0; $j < count($mat1[0]); $j++)
{
echo $mat1[$i][$j] . " ";
}
echo "<br/>";
}
echo "</h1>";
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 29
echo "<h1>Matrix B:<br/>";
for($i = 0; $i < count($mat2); $i++)
{
for ($j = 0; $j < count($mat2[0]); $j++)
{
echo $mat2[$i][$j] . " ";
}
echo "<br/>";
}
echo "</h1>";
$res=array();
for($i = 0; $i < count($mat1); $i++)
for($j = 0; $j < count($mat1[0]); $j++)
{
$res[$i][$j]=$mat1[$i][$j]+$mat2[$i][$j];
}
echo "<h1>A + B :<br/>";
for($i = 0; $i < count($res); $i++)
{
for ($j = 0; $j < count($res[0]); $j++)
{
echo $res[$i][$j] . " ";
}
echo "<br/>";
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 30
}
echo "</h1>";
Output :
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 31
9. Write a PHP program named states.py that declares a variable
states with value "Mississippi Alabama Texas Massachusetts Kansas".
write a PHP program that does the following:
a) Search for a word in variable states that ends in xas. Store
this word in element 0 of a list named statesList.
b) Search for a word in states that begins with k and ends in s.
Perform a case-insensitive comparison. [Note: Passing re.Ias a
second parameter to method compile performs a case-insensitive
comparison.] Store this word in element1 of statesList.
c) Search for a word in states that begins with M and ends in
s. Store this word in element 2 of the list.
d) Search for a word in states that ends in a. Store this word in
element 3 of the list.
index.php
<html>
<head>
<title>Pattern Matching using
python</title> </head>
<body>
<?php
$res=shell_exec("python PythonServer/states.py");
$states=explode("n",$res); //in python print embed n at the
end echo "Statement is : <b>$states[4]</b><br/>";
echo "Word that end with xas : <b>$states[0]</b><br/>";
echo "Word that Starts with k and end with s (Case Insensitive):
<b>$states[1]</b><br/>";
echo "Word that Starts with M and end with s :
<b>$states[2]</b><br/>";
echo "Word that end with a :
<b>$states[3]</b>"; ?>
</body>
</html>
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 32
States.py
import re
states="Mississippi Alabama Texas Massachusetts Kansas"
statesArr=states.split() # splits the sentence into words
statesList=list() # Creates an empty List
for val in statesArr:
if(re.search('xas$',val)):
#note: Indentation is imp in
python
statesList.append(val)
for val in statesArr:
if(re.search('^k.*s$',val,re.I)):
statesList.append(val)
for val in statesArr:
if(re.search('^M.*s$',val)):
statesList.append(val)
for val in statesArr:
if(re.search('a$',val)):
statesList.append(val)
for val in statesList:
print(val)
print(states);
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 33
Instruction :
Install Python in terminal / command prompt.
Create a folder named “PythonServer” in the same directory where
“index.php” has been located. And then place the “states.py” file
inside “PythonServer” folder.
This is to assume that “state.py” has been fetched from some
python server, which has been located somewhere on the internet.
Output :
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 34
10. Write a PHP program to sort the student records which are stored
in the database using selection sort.
index.php
<html>
<head>
<title>Select Sort on student
records</title> <style type="text/css">
h1 {text-align: center}
</style>
</head>
<body>
<h1>Merge Sort on sample student data</h1>
<form action="" method="post">
<h1>Sort By :
<select name="field">
<option value="" disabled selected>Choose
Field</option> <option value="name">Name</option>
<option value="usn">USN</option>
<option value="year">Year</option>
<option value="marks">Marks</option>
<option value="coll">College</option>
</select>
</h1>
<h1>
<input type="submit" name="submit" value="Submit">
<input type="reset" name="reset" value="Reset">
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 35
</h1>
</form>
<?php
function selection_sort($data,$keys)
{
for($i=0; $i<count($data)-1; $i++)
{
$min = $i;
for($j=$i+1; $j<count($data); $j++)
{
if ($data[$j]<$data[$min])
{
$min = $j;
}
}
$data = swap_positions($data, $i, $min);
$keys = swap_positions($keys, $i, $min);
}
return $keys;
}
function swap_positions($data1, $left, $right)
{
$temp = $data1[$right];
$data1[$right] = $data1[$left];
$data1[$left] = $temp;
return $data1;
}
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 36
include 'sql.php';
$str="select * from studentdetails";
$res=mysqli_query($sql,$str);
$field="none";
$myarr=[];
$original=[];
$i=1;
while($arr=mysqli_fetch_assoc($res))
{
$myarr[]=$arr;
}
if(isset($_POST['submit']) && isset($_POST['field']))
{
$field=$_POST['field'];
$original=array_column($myarr,$field,'id');
// Create Associate array with
(key,value)=('id',$feild)
$orginalKey=array_keys($original);
$originalVal=array_values($original);
$sortedkeys=selection_sort($originalVal,$orginalKey);
$myarr=[];
foreach ($sortedkeys as $key)
{
$str="select * from studentdetails WHERE
id='$key'"; $res=mysqli_query($sql,$str);
$myarr[]=mysqli_fetch_assoc($res);
}
}
?>
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 37
<table border="1" width="80%"
align="center"> <tr>
<th colspan="6">
Student Details [Sorted by: <?php echo
$field;?>] </th>
</tr>
<tr>
<th>No</th>
<th>Name</th>
<th>USN</th>
<th>Year</th>
<th>Marks</th>
<th>College</th>
</tr>
<?php foreach ($myarr as $arr): ?>
<tr>
<td><?php echo $i++; ?></td>
<td><?php echo $arr['name']; ?></td>
<td><?php echo $arr['usn']; ?></td>
<td><?php echo $arr['year']; ?></td>
<td><?php echo $arr['marks']; ?></td>
<td><?php echo $arr['coll']; ?></td>
</tr>
<?php endforeach; ?>
</table>
</body>
</html>
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 38
sql.php
<?php
$sql=mysqli_connect("localhost","root","","prog10db");
?>
Database Procedure :
1. Creating Database :
CREATE DATABASE prog10db;
2. Creating table :
CREATE TABLE studentdetails (
id int AUTO_INCREMENT,
name varchar(100),
usn varchar(50),
year int,
marks int,
coll varchar(200),
PRIMARY KEY (id)
);
3. Insert 5 sample data into table :
INSERT INTO studentdetails VALUES
(0,'Raj','4sh12cs001',2012,75,'Shree Devi Institute of Tech'),
(0,'Suresh','4sh10cs002',2010,55,'Shree Devi Institute of Tech'),
(0,'Ram','4sr11cs001',2011,75,'Srinivas Institute of Tech'),
(0,'Som','4sj15cs001',2015,35,'StJoseph Collge of Engg'),
(0,'Bhim','4ca14cs001',2014,75,'Canara Collage of Engg');
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 39
Output :
(a) Without applying any sort
(b) Sorting the data based on USN
PROGRAMMINGTHE WEB LABORATORY 2021
FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 40
(c) Sorting the data based on MARKS

Mais conteúdo relacionado

Mais procurados

Testing Javascript with Jasmine
Testing Javascript with JasmineTesting Javascript with Jasmine
Testing Javascript with JasmineTim Tyrrell
 
What’s new in ECMAScript 6.0
What’s new in ECMAScript 6.0What’s new in ECMAScript 6.0
What’s new in ECMAScript 6.0Eyal Vardi
 
Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::ManagerJay Shirley
 
Tools for Solving Performance Issues
Tools for Solving Performance IssuesTools for Solving Performance Issues
Tools for Solving Performance IssuesOdoo
 
ES6 patterns in the wild
ES6 patterns in the wildES6 patterns in the wild
ES6 patterns in the wildJoe Morgan
 
New Framework - ORM
New Framework - ORMNew Framework - ORM
New Framework - ORMOdoo
 
javascript function & closure
javascript function & closurejavascript function & closure
javascript function & closureHika Maeng
 
Functional Structures in PHP
Functional Structures in PHPFunctional Structures in PHP
Functional Structures in PHPMarcello Duarte
 
Unit testing with mocha
Unit testing with mochaUnit testing with mocha
Unit testing with mochaRevath S Kumar
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxMichelangelo van Dam
 
Jasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishyJasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishyIgor Napierala
 
Beginning PHPUnit
Beginning PHPUnitBeginning PHPUnit
Beginning PHPUnitJace Ju
 
10 Catalyst Tips
10 Catalyst Tips10 Catalyst Tips
10 Catalyst TipsJay Shirley
 
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)Ankit Gupta
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11Michelangelo van Dam
 

Mais procurados (20)

Testing Javascript with Jasmine
Testing Javascript with JasmineTesting Javascript with Jasmine
Testing Javascript with Jasmine
 
What’s new in ECMAScript 6.0
What’s new in ECMAScript 6.0What’s new in ECMAScript 6.0
What’s new in ECMAScript 6.0
 
Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::Manager
 
Tools for Solving Performance Issues
Tools for Solving Performance IssuesTools for Solving Performance Issues
Tools for Solving Performance Issues
 
ES6 patterns in the wild
ES6 patterns in the wildES6 patterns in the wild
ES6 patterns in the wild
 
Java and xml
Java and xmlJava and xml
Java and xml
 
New Framework - ORM
New Framework - ORMNew Framework - ORM
New Framework - ORM
 
project3
project3project3
project3
 
javascript function & closure
javascript function & closurejavascript function & closure
javascript function & closure
 
Functional Structures in PHP
Functional Structures in PHPFunctional Structures in PHP
Functional Structures in PHP
 
Unit testing with mocha
Unit testing with mochaUnit testing with mocha
Unit testing with mocha
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
 
ES2015 New Features
ES2015 New FeaturesES2015 New Features
ES2015 New Features
 
Jasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishyJasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishy
 
Beginning PHPUnit
Beginning PHPUnitBeginning PHPUnit
Beginning PHPUnit
 
10 Catalyst Tips
10 Catalyst Tips10 Catalyst Tips
10 Catalyst Tips
 
F
FF
F
 
PHPSpec BDD Framework
PHPSpec BDD FrameworkPHPSpec BDD Framework
PHPSpec BDD Framework
 
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11
 

Semelhante a Web lab programs

CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairMark
 
Serverless Functions and Vue.js
Serverless Functions and Vue.jsServerless Functions and Vue.js
Serverless Functions and Vue.jsSarah Drasner
 
Java.script
Java.scriptJava.script
Java.scriptg Nama
 
Webdesing lab part-b__java_script_
Webdesing lab part-b__java_script_Webdesing lab part-b__java_script_
Webdesing lab part-b__java_script_Shivanand Algundi
 
Going crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHPGoing crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHPMariano Iglesias
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical filePranav Ghildiyal
 
JAVASCRIPT PROGRAM.pdf
JAVASCRIPT PROGRAM.pdfJAVASCRIPT PROGRAM.pdf
JAVASCRIPT PROGRAM.pdfAAFREEN SHAIKH
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScriptniklal
 
02 Introduction to Javascript
02 Introduction to Javascript02 Introduction to Javascript
02 Introduction to Javascriptcrgwbr
 
WEB DESIGN PRACTICLE bca
WEB DESIGN PRACTICLE bcaWEB DESIGN PRACTICLE bca
WEB DESIGN PRACTICLE bcaYashKoli22
 
YASH HTML CODES
YASH HTML CODESYASH HTML CODES
YASH HTML CODESYashKoli22
 
YASH HTML CODE
YASH HTML CODE YASH HTML CODE
YASH HTML CODE YashKoli22
 
Oracle APEX Performance
Oracle APEX PerformanceOracle APEX Performance
Oracle APEX PerformanceScott Wesley
 
sodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfsodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfMuhammadMaazShaik
 
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRaimonds Simanovskis
 
Sydney Oracle Meetup - execution plans
Sydney Oracle Meetup - execution plansSydney Oracle Meetup - execution plans
Sydney Oracle Meetup - execution planspaulguerin
 
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6FrontDays
 

Semelhante a Web lab programs (20)

CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love Affair
 
Serverless Functions and Vue.js
Serverless Functions and Vue.jsServerless Functions and Vue.js
Serverless Functions and Vue.js
 
Java.script
Java.scriptJava.script
Java.script
 
Html
HtmlHtml
Html
 
Webdesing lab part-b__java_script_
Webdesing lab part-b__java_script_Webdesing lab part-b__java_script_
Webdesing lab part-b__java_script_
 
Going crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHPGoing crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHP
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
 
JAVASCRIPT PROGRAM.pdf
JAVASCRIPT PROGRAM.pdfJAVASCRIPT PROGRAM.pdf
JAVASCRIPT PROGRAM.pdf
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
 
02 Introduction to Javascript
02 Introduction to Javascript02 Introduction to Javascript
02 Introduction to Javascript
 
WEB DESIGN PRACTICLE bca
WEB DESIGN PRACTICLE bcaWEB DESIGN PRACTICLE bca
WEB DESIGN PRACTICLE bca
 
YASH HTML CODES
YASH HTML CODESYASH HTML CODES
YASH HTML CODES
 
YASH HTML CODE
YASH HTML CODE YASH HTML CODE
YASH HTML CODE
 
Oracle APEX Performance
Oracle APEX PerformanceOracle APEX Performance
Oracle APEX Performance
 
sodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfsodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdf
 
Arrays
ArraysArrays
Arrays
 
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
 
Sydney Oracle Meetup - execution plans
Sydney Oracle Meetup - execution plansSydney Oracle Meetup - execution plans
Sydney Oracle Meetup - execution plans
 
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
 

Mais de SRINIVASUNIVERSITYEN (7)

Sucet os module_5_notes
Sucet os module_5_notesSucet os module_5_notes
Sucet os module_5_notes
 
Sucet os module_4_notes
Sucet os module_4_notesSucet os module_4_notes
Sucet os module_4_notes
 
Sucet os module_3_notes
Sucet os module_3_notesSucet os module_3_notes
Sucet os module_3_notes
 
Sucet os module_2_notes
Sucet os module_2_notesSucet os module_2_notes
Sucet os module_2_notes
 
os mod1 notes
 os mod1 notes os mod1 notes
os mod1 notes
 
Aca
AcaAca
Aca
 
Cn lab manual sb 19_scsl56 (1)
Cn lab manual sb 19_scsl56 (1)Cn lab manual sb 19_scsl56 (1)
Cn lab manual sb 19_scsl56 (1)
 

Último

Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 

Último (20)

Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 

Web lab programs

  • 1. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 1 1. Write a JavaScript to design a simple calculator to perform the following operations: sum, product, difference and quotient. index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Simple Calculator</title> <script type="text/javascript"> var op1= 0,op2= 0,operator="",res="",from=""; function reset() { document.getElementById('res').value = ""; op1=0;op2=0;operator="";res="";from=""; } function insertOperand(operand) { if(from == "calculate") reset(); else if(from == "operator") document.getElementById('res').value = ""; document.getElementById('res').value+=ope rand; from = "operand"; } function insertOperator(op) { if(op1 == 0) { op1=document.getElementById('res').value;
  • 2. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 2 } else { if(from == "operand") { calculate(); } } operator=op; from="operator"; } function calculate() { op2=document.getElementById('res').value; op1=parseInt(op1); op2=parseInt(op2); switch (operator) { case '+':res=op1+op2; break; case '-' :res=op1-op2; break; case '*':res=op1*op2; break; case '/': if(op2 == 0) res=0; else
  • 3. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 3 res=parseInt(op1/op2); break; } document.getElementById('res').value= res; op1=res; op2=0; operator=""; from="calculate"; } </script> <style type="text/css"> input {width: 100%} h1 {text-align: center} </style> </head> <body onload="reset()"> <h1>Simple Calculator</h1> <table align="center" border="1"> <tr> <td colspan="5"><input type="text" id="res" name="res" value="" /></td> </tr> <tr> <td><input type="button" value="7" onclick="insertOperand('7')"/></td> <td><input type="button" value="8" onclick="insertOperand('8')" /></td> <td><input type="button" value="9" onclick="insertOperand('9')" /></td> <td><input type="button" value="+" onclick="insertOperator('+')" /></td> <td><input type="button" value="-" onclick="insertOperator('-')" /></td>
  • 4. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 4 </tr> <tr> <td><input type="button" value="4" onclick="insertOperand('4')" /></td> <td><input type="button" value="5" onclick="insertOperand('5')" /></td> <td><input type="button" value="6" onclick="insertOperand('6')" /></td> <td><input type="button" value="*" onclick="insertOperator('*')" /></td> <td><input type="button" value="/" onclick="insertOperator('/')"/></td> </tr> <tr> <td><input type="button" value="1" onclick="insertOperand('1')" /></td> <td><input type="button" value="2" onclick="insertOperand('2')" /></td> <td><input type="button" value="3" onclick="insertOperand('3')" /></td> <td><input type="button" value="0" onclick="insertOperand('0')" /></td> <td><input type="button" value="=" onclick="calculate()" /></td> . </tr> <tr> <td colspan="5"><input type="button" size="100%" value="CLEAR" onclick="reset()" /> </td> </tr> </table> </body> </html> OUTPUT:
  • 5. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 5 2. Write a JavaScript that calculates the squares and cubes of the numbers from 0 to 10 and outputs HTML text that displays the resulting values in an HTML table format. index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Program for Squares and Cubes</title> <style type="text/css"> table,h1 {text-align: center} </style> </head> <body> <h1>Program to find Square and Cube</h1> <script type="text/javascript"> var mytable="<table border='1' align='center'> <tr> <th>Number</th> <th>Square</th> <th>Cube</th> </tr>"; var square= 0,cube=0; for(var i=0;i<=10;i++) { square=i*i; cube=i*i*i; mytable+="<tr><td>"+i+"</td><td>"+square+"</td> <td>"+cube+"</td></tr>" } mytable+="</table>"; document.write(mytable); </script>
  • 6. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 6 </body> </html> Output :
  • 7. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 7 3. Write a JavaScript code that displays text “TEXT-GROWING” with increasing font size in the interval of 100ms in RED COLOR, when the font size reaches 50pt it displays “TEXT-SHRINKING” in BLUE color. Then the font size decreases to 5pt. index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Prog for Text Animation</title> <script type="text/javascript"> function animate() { var val=window.getComputedStyle(document.getElementById('text') ).fontSize; var fontsize=parseInt(val); var state="growing"; var timer=setInterval(textanimate,100); function textanimate() { if(state=="growing") { fontsize++; document.getElementById('text').innerHTML="TEXT GROWING"; document.getElementById('text').style.color="red"; document.getElementById('text').style.fontSize=fontsize+ "pt";
  • 8. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 8 } if(state=="shrinking") { fontsize--; document.getElementById('text').innerHTML="TEXT SHRINKING"; document.getElementById('text').style.color="blue"; document.getElementById('text').style.fontSize=fontsize+ "pt"; } if(fontsize==50) { state="shrinking" } if(fontsize==5) { clearInterval(timer); } } } </script> </head> <body onload="animate()"> <h1 style="text-align: center"> Program for Increasing / Decreasing size of a text </h1> <p style="text-align: center;" id="text"></p> </body> </html>
  • 9. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 9 OUTPUT: (a) Animation for text growing (b) Animation for text shrinking
  • 10. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 10 4. Develop and demonstrate a HTML5 file that includes JavaScript script that uses functions for the following problems: a. Parameter: A string b. Output: The position in the string of the left-most vowel c. Parameter: A number d. Output: The number with its digits in the reverse order index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Program to find leftmost vowel and digits in reverse order</title> <script type="text/javascript"> function validate() { var inp=document.getElementById('val').value; if(isNaN(inp)) findVowel(inp); else findReverse(inp); } function findVowel(inp) { var str=inp.toLowerCase(); var pos=0,ch=""; for(var i=0;i<str.length;i++) { ch=str.charAt(i); if(ch=="a"||ch=="e"||ch=="i"||ch=="o"||ch=="u") {
  • 11. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 11 pos=i+1; break; } } if(pos==0) alert("Vowel not found"); else alert("Position of Left Most Vowel in the string : "+pos); } function findReverse(inp) { var num=parseInt(inp); var temp=num; var rem= 0,rev= 0; while(num>0) { rem=num%10; rev=rev*10+rem; num=parseInt(num/10); } alert("Number : "+temp+"nReverse Order : "+rev); } </script> </head> <body > <h1>
  • 12. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 12 Program to find left most vowel or Digits in reverse order </h1> <input type="text" name="val" id="val" placeholder="Enter String or Digits"> <input type="button" value="submit" onclick="validate()"> </body> </html> Output : (a) When you enter the string as input (b) When you enter the digits as input
  • 13. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 13 5. Design an XML document to store information about a student in an engineering college affiliated to VTU. The information must include USN, Name, and Name of the College, Branch, Year of Joining, and email id. Make up sample data for 3 students. Create a CSS style sheet and use it to display the document. 5.xml <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/css" href="5.css"?> <!DOCTYPE student [ <!ELEMENT student_info (h1,h2+,ad+)> <!ELEMENT ad (label)> <!ELEMENT usn (#PCDATA)> <!ELEMENT name (#PCDATA)> <!ELEMENT col (#PCDATA)> <!ELEMENT branch (#PCDATA)> <!ELEMENT year (#PCDATA)> <!ELEMENT email (#PCDATA)> <!ELEMENT label (#PCDATA|usn|name|col|branch|year|email)*> <!ELEMENT h2 (#PCDATA)> <!ELEMENT h1 (#PCDATA)>]> <student_info> <h1>Student information</h1> <h2>Student1</h2> <ad><label>USN:<usn>4ES15CS001</usn></label></ad> <ad><label>NAME:<name>AAA</name></label></ad> <ad><label>COLLEGE:<col>SSE, MUKKA</col></label></ad>
  • 14. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 14 <ad><label>BRANCH:<branch>CSE</branch></label></ad> <ad><label>YEAR:<year>2011</year></label></ad> <ad><label>EMAIL:<email>abc@gmail.com</email></label></ad> <h2>Student2</h2> <ad><label>USN:<usn>4ES15IS002</usn></label></ad> <ad><label>NAME:<name>BBB</name></label></ad> <ad><label>COLLEGE:<col>SSE, MUKKA</col></label></ad> <ad><label>BRANCH:<branch>ISE</branch></label></ad> <ad><label>YEAR:<year>2012</year></label></ad> <ad><label>EMAIL:<email>efg@gmail.com</email></label></ad> <h2>Student3</h2> <ad><label>USN:<usn>4ES15CS003</usn></label></ad> <ad><label>NAME:<name>CCC</name></label></ad> <ad><label>COLLEGE:<col>SSE, MUKKA</col></label></ad> <ad><label>BRANCH:<branch>CSE</branch></label></ad> <ad><label>YEAR:<year>2013</year></label></ad> <ad><label>EMAIL:<email>hij@gmail.com</email></label></ad> </student_info> 5.css h1 {color:green;font-size:50px;} h2 {display:block;margin-left:40px;color:brown;font-size:40px;} ad {display:block;margin-left:80px;margin- top:20px;color:blue;font-size:20px;} usn {color:red;margin-left:20px;font-size:20px;} name {color:red;margin-left:20px;font-size:20px;} col {color:red;margin-left:20px;font-size:20px;} branch {color:red;margin-left:20px;font-size:20px;} year
  • 15. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 15 {color:red;margin-left:20px;font-size:20px;} email {color:red;margin-left:20px;font-size:20px;} Output :
  • 16. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 16 6.Write a PHP program to keep track of the number of visitors visiting the web page and to display this count of visitors, with proper headings. index.php <html> <head> <title>Visitors Count</title> <style type="text/css"> h1,h2 {text-align: center} </style> </head> <body> <h1>Welcome to MY WEB PAGE</h1> <?php $file="count.txt"; $handle=fopen($file,'r') or die("Cannot Open File : $file"); $count=fread($handle,10); fclose($handle); $count++; echo "<h2>No of visitors who visited this page : $count </h2>"; $handle=fopen($file,'w') or die("Cannot Open File : $file"); fwrite($handle,$count); fclose($handle); ?> </body> </html>
  • 17. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 17 Instruction : Create an empty file named count.txt in the same folder before executing. Output :
  • 18. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 18 7. Write a PHP program to display a digital clock which displays the current time of the server. index.php <html> <head> <meta http-equiv="refresh" content="1"> <title>Digital Clock</title> <style type="text/css"> h1 {text-align: center} </style> </head> <body> <?php echo "<h1>Digital Clock</h1>"; echo "<hr/>"; echo "<h1>".date('h:i:s A')."</h1>"; echo "<hr/>"; ?> </body> </html>
  • 19. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 19 Output :
  • 20. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 20 8. Write the PHP programs to do the following: a. Implement simple calculator operations. b. Find the transpose of a matrix. c. Multiplication of two matrices. d. Addition of two matrices. 8a.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Simple Calculator</title> </head> <body> <form action="8a.php" method="post"> <h1>Simple Calculator</h1> <p>First Operand: <input type="text" name="op1" /></p> <p>Choose Operator: <input type="radio" name="operator" checked="checked" value="+" /> Add(+) <input type="radio" name="operator" value="-" /> Subtract(-) <input type="radio" name="operator" value="*" /> Multiply(*) <input type="radio" name="operator" value="/" /> Divide(/) </p> <p>Second Operand: <input type="text" name="op2"></p> <p><input type="submit" name="submit" value="Submit"> <input type="reset" name="submit" value="Reset"></p> </form> </body>
  • 21. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 21 </html> 8a.php <html> <head> <title>Result Page</title> <style type="text/css"> h1,h2 {text-align: center} </style> </head> <body> <?php $op1=$_POST['op1']; $op2=$_POST['op2']; $operator=$_POST['operator']; switch($operator) { case '+':$res=$op1+$op2; break; case '-':$res=$op1-$op2; break; case '*':$res=$op1*$op2; break; case '/':if($op2==0) $res=0;
  • 22. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 22 else $res=$op1/$op2; break; } echo "<h1>Simple Calculator</h1>"; echo "<h2>".$op1.$operator.$op2."=".$res."</h2>"; ?> </body> Output : (a) HTML input page
  • 23. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 23 (b) PHP output/result page 8b.php <?php $mat=Array(Array(1,2), Array(4,5), Array(7,8)); //Initializing Array in PHP $transpose=Array(); //Creating empty array in PHP echo "<html><head><title>Matrix Transpose</title></head><body>"; echo "<h1>Matrix is:<br/>"; for($i = 0; $i < count($mat); $i++) { for ($j = 0; $j < count($mat[0]); $j++) { echo $mat[$i][$j] . " "; } echo "</br/>"; } echo "</h1>";
  • 24. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 24 for($i = 0; $i < count($mat); $i++) //calculation for Transpose for($j = 0; $j < count($mat[0]); $j++) { $transpose[$j][$i]=$mat[$i][$j ]; } echo "<h1>Transpose of a Matrix is:<br/>"; for($i = 0; $i < count($transpose); $i++) { for ($j = 0; $j < count($transpose[0]); $j++) { echo $transpose[$i][$j] . " "; } echo "<br/>"; } echo "</h1>"; echo "</body></html>"; ?> Output :
  • 25. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SUCET, MUKKA Page 25 8c.php <?php $ mat1=Array(Array(1,2), Array(3,4), Array(5,6) ); $mat2=Array(Array(2,4,8), Array(1,3,5) ); echo "<html><head><title>Matrix Multiplication</title></head><body>"; if(count($mat1[0])!=count($mat2)) { //column(1st matrix) != row(2nd matrix)
  • 26. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 26 echo "<h1>Incompatible Matrices</h1>"; exit(0); } $res=array(); echo "<h1>Matrix A:<br/>"; for($i = 0; $i < count($mat1); $i++) { for ($j = 0; $j < count($mat1[0]); $j++) { echo $mat1[$i][$j] . " "; } echo "<br/>"; } echo "</h1>"; echo "<h1>Matrix B:<br/>"; for($i = 0; $i < count($mat2); $i++) { for ($j = 0; $j < count($mat2[0]); $j++) { echo $mat2[$i][$j] . " "; } echo "<br/>"; } echo "</h1>";
  • 27. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 27 for($i = 0; $i < count($mat1); $i++) for($j = 0; $j < count($mat2[0]); $j++) { $res[$i][$j]=0; for($k=0;$k<count($mat2);$k++) $res[$i][$j]=$res[$i][$j]+$mat1[$i][$k]*$mat2[$k][$j]; } echo "<h1>A x B:<br/>"; for($i = 0; $i < count($res); $i++) { for ($j = 0; $j < count($res); $j++) { echo $res[$i][$j] . " "; } echo "<br/>"; } echo "</h1>"; echo "</body></html>"; Output :
  • 28. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 28 8d.php <?php $mat1=Array(Array(1,2), Array(3,4), Array(5,6)); $mat2=Array(Array(1,1), Array(2,2), Array(3,3)); echo "<html><head><title>Matrix Addition</title></head><body>"; if((count($mat1)!=count($mat2))||(count($mat1[0])!=count($mat2[0]))) { echo "<h1>Incompatible Matrices</h1>"; exit(0); } echo "<h1>Matrix A:<br/>"; for($i=0;$i<count($mat1);$i++) { for ($j = 0; $j < count($mat1[0]); $j++) { echo $mat1[$i][$j] . " "; } echo "<br/>"; } echo "</h1>";
  • 29. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 29 echo "<h1>Matrix B:<br/>"; for($i = 0; $i < count($mat2); $i++) { for ($j = 0; $j < count($mat2[0]); $j++) { echo $mat2[$i][$j] . " "; } echo "<br/>"; } echo "</h1>"; $res=array(); for($i = 0; $i < count($mat1); $i++) for($j = 0; $j < count($mat1[0]); $j++) { $res[$i][$j]=$mat1[$i][$j]+$mat2[$i][$j]; } echo "<h1>A + B :<br/>"; for($i = 0; $i < count($res); $i++) { for ($j = 0; $j < count($res[0]); $j++) { echo $res[$i][$j] . " "; } echo "<br/>";
  • 30. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 30 } echo "</h1>"; Output :
  • 31. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 31 9. Write a PHP program named states.py that declares a variable states with value "Mississippi Alabama Texas Massachusetts Kansas". write a PHP program that does the following: a) Search for a word in variable states that ends in xas. Store this word in element 0 of a list named statesList. b) Search for a word in states that begins with k and ends in s. Perform a case-insensitive comparison. [Note: Passing re.Ias a second parameter to method compile performs a case-insensitive comparison.] Store this word in element1 of statesList. c) Search for a word in states that begins with M and ends in s. Store this word in element 2 of the list. d) Search for a word in states that ends in a. Store this word in element 3 of the list. index.php <html> <head> <title>Pattern Matching using python</title> </head> <body> <?php $res=shell_exec("python PythonServer/states.py"); $states=explode("n",$res); //in python print embed n at the end echo "Statement is : <b>$states[4]</b><br/>"; echo "Word that end with xas : <b>$states[0]</b><br/>"; echo "Word that Starts with k and end with s (Case Insensitive): <b>$states[1]</b><br/>"; echo "Word that Starts with M and end with s : <b>$states[2]</b><br/>"; echo "Word that end with a : <b>$states[3]</b>"; ?> </body> </html>
  • 32. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 32 States.py import re states="Mississippi Alabama Texas Massachusetts Kansas" statesArr=states.split() # splits the sentence into words statesList=list() # Creates an empty List for val in statesArr: if(re.search('xas$',val)): #note: Indentation is imp in python statesList.append(val) for val in statesArr: if(re.search('^k.*s$',val,re.I)): statesList.append(val) for val in statesArr: if(re.search('^M.*s$',val)): statesList.append(val) for val in statesArr: if(re.search('a$',val)): statesList.append(val) for val in statesList: print(val) print(states);
  • 33. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 33 Instruction : Install Python in terminal / command prompt. Create a folder named “PythonServer” in the same directory where “index.php” has been located. And then place the “states.py” file inside “PythonServer” folder. This is to assume that “state.py” has been fetched from some python server, which has been located somewhere on the internet. Output :
  • 34. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 34 10. Write a PHP program to sort the student records which are stored in the database using selection sort. index.php <html> <head> <title>Select Sort on student records</title> <style type="text/css"> h1 {text-align: center} </style> </head> <body> <h1>Merge Sort on sample student data</h1> <form action="" method="post"> <h1>Sort By : <select name="field"> <option value="" disabled selected>Choose Field</option> <option value="name">Name</option> <option value="usn">USN</option> <option value="year">Year</option> <option value="marks">Marks</option> <option value="coll">College</option> </select> </h1> <h1> <input type="submit" name="submit" value="Submit"> <input type="reset" name="reset" value="Reset">
  • 35. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 35 </h1> </form> <?php function selection_sort($data,$keys) { for($i=0; $i<count($data)-1; $i++) { $min = $i; for($j=$i+1; $j<count($data); $j++) { if ($data[$j]<$data[$min]) { $min = $j; } } $data = swap_positions($data, $i, $min); $keys = swap_positions($keys, $i, $min); } return $keys; } function swap_positions($data1, $left, $right) { $temp = $data1[$right]; $data1[$right] = $data1[$left]; $data1[$left] = $temp; return $data1; }
  • 36. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 36 include 'sql.php'; $str="select * from studentdetails"; $res=mysqli_query($sql,$str); $field="none"; $myarr=[]; $original=[]; $i=1; while($arr=mysqli_fetch_assoc($res)) { $myarr[]=$arr; } if(isset($_POST['submit']) && isset($_POST['field'])) { $field=$_POST['field']; $original=array_column($myarr,$field,'id'); // Create Associate array with (key,value)=('id',$feild) $orginalKey=array_keys($original); $originalVal=array_values($original); $sortedkeys=selection_sort($originalVal,$orginalKey); $myarr=[]; foreach ($sortedkeys as $key) { $str="select * from studentdetails WHERE id='$key'"; $res=mysqli_query($sql,$str); $myarr[]=mysqli_fetch_assoc($res); } } ?>
  • 37. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 37 <table border="1" width="80%" align="center"> <tr> <th colspan="6"> Student Details [Sorted by: <?php echo $field;?>] </th> </tr> <tr> <th>No</th> <th>Name</th> <th>USN</th> <th>Year</th> <th>Marks</th> <th>College</th> </tr> <?php foreach ($myarr as $arr): ?> <tr> <td><?php echo $i++; ?></td> <td><?php echo $arr['name']; ?></td> <td><?php echo $arr['usn']; ?></td> <td><?php echo $arr['year']; ?></td> <td><?php echo $arr['marks']; ?></td> <td><?php echo $arr['coll']; ?></td> </tr> <?php endforeach; ?> </table> </body> </html>
  • 38. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 38 sql.php <?php $sql=mysqli_connect("localhost","root","","prog10db"); ?> Database Procedure : 1. Creating Database : CREATE DATABASE prog10db; 2. Creating table : CREATE TABLE studentdetails ( id int AUTO_INCREMENT, name varchar(100), usn varchar(50), year int, marks int, coll varchar(200), PRIMARY KEY (id) ); 3. Insert 5 sample data into table : INSERT INTO studentdetails VALUES (0,'Raj','4sh12cs001',2012,75,'Shree Devi Institute of Tech'), (0,'Suresh','4sh10cs002',2010,55,'Shree Devi Institute of Tech'), (0,'Ram','4sr11cs001',2011,75,'Srinivas Institute of Tech'), (0,'Som','4sj15cs001',2015,35,'StJoseph Collge of Engg'), (0,'Bhim','4ca14cs001',2014,75,'Canara Collage of Engg');
  • 39. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 39 Output : (a) Without applying any sort (b) Sorting the data based on USN
  • 40. PROGRAMMINGTHE WEB LABORATORY 2021 FARHA ANJUM, ASST PROF, DEPT OF CSE, SSE, MUKKA Page 40 (c) Sorting the data based on MARKS