Wednesday, 27 December 2017

AWT-Slip5

1) Write an PHP script to search customer name from customer.dat file(Use AJAX concept)

customer.php

<html>

<head>

<script>

var XHRobj=false;

 if(window.XMLHttpRequest)

 {

 XHRobj=new XMLHttpRequest();

 }

 else if(window.ActiveXObject)

 {

XHRobj=new ActiveXObject("Microsoft.XMLHTTP");

 }

function fetchdata(datasource,divID)

{

if(XHRobj)

{

XHRobj.open("GET",datasource);

XHRobj.onreadystatechange = function()

{

if (XHRobj.readyState == 4 && XHRobj.status == 200)

 {

document.getElementById("divID").innerHTML = XHRobj.responseText;

  }

}

 XHRobj.send(null);

  }

 }       

</script>

</head>

<body>

<p><b>Customer Details:</b></p>

<form>

<?php

$database="archana"; //database name

 $con = mysql_connect("localhost","root" ,"");//for wamp 3rd feild is balnk

 if (!$con)

{

die('Could not connect: ' . mysql_error());

 }

 mysql_select_db("$database", $con);

 $result=mysql_query("SELECT * from `customer` ");

?>

<form action=".php" method="get">

customer Name: <input type="text" name="cname"><br>

<input type="button" name="ok" onclick="fetchdata('customer.dat','myDiv')">

</form>

<div id="myDiv"><b> Customer info......</b></div>

</body>

</html>

 

customer.dat

as

asd

asdf

 

------

customer.php

 <?php

$nm=$_GET['srch'];

$fp=fopen("customer.dat","r");

echo "<table border=1><tr><th>CId</th><th>customer Name</th></tr>";

while($res=fscanf($fp,"%s %s"))

{

if($res[1]==$nm)

{

echo "<tr><td>".$res[0]."</td><td>".$res[1]."</td><tr>";

}

}

echo "</table>";

?>

customer.html

 

<html>

<head>

<script>

function search()

{

s=document.getElementById('txt1').value;

ob1=new XMLHttpRequest();

ob1.onreadystatechange=function()

{

if(ob1.readyState==4 && ob1.status==200)

{

document.getElementById('o').innerHTML=ob.responseText;

}

}

ob1.open("GET","customer.php?srch="+s);

ob1.send();

}

</script>

</head>

<body>

<input type=text id=txt1 placeholder="Enter Customer name"></br>

<input type=button value="Search" onclick="search()">

<h1 id="o">Output</h1>

</body>

</html>

 

 

2)Define a class Employee having privatemembers – id, name, department, salary. Define parameterized constructors.Create a subclass called “Manager” with private member bonus. Create 6 objectsof the Manager class and display the details of the manager having the maximumtotal salary (salary + bonus).  

 <?php

 class Employee

 {

 private $eid,$ename,$edept,$sal;

 function __construct($a,$b,$c,$d)

 {

 $this->eid=$a;

 $this->ename=$b;

 $this->edept=$c;

 $this->sal=$d;

 }

 public function getdata()

 {

 return $this->sal;

 }

 public function display()

 {

 echo $this->eid."  ";

 echo $this->ename." ";

 echo $this->edept." ";

 }

 }

 class Manager extends Employee

 {

 private $bonus;

 public static $total1=0;

 function __construct($a,$b,$c,$d,$e)

 {

 parent::__construct($a,$b,$c,$d);

 $this->bonus=$e;

 }

 public function max($ob)

 {

 $sal=$this->getdata();

 $total=$sal+$this->bonus;

 if($total>self::$total1)

 {

 self::$total1=$total;

 return $this;

 }

 else

 {

 return $ob;

 }

 }

 public function display()

 {

 parent::display();

 echo self::$total1;

 }

}

 $ob=new Manager(0,"ABC","",0,0);

 $ob1=new Manager(1,"Archana","HR",28000,2000);

 $ob=$ob1->max($ob);

 $ob2=new Manager(2,"Adhira","Tester",30000,2500);

 $ob=$ob2->max($ob);

 $ob3=new Manager(3,"Amol","PM",32000,3000);

 $ob=$ob3->max($ob);

 $ob->display();

 ?>