Sunday, 8 May 2022

Advance PHP-sLIP23b -Write Ajax program to print Movie details by selecting an Actor's name. Create table MOVIE and ACTOR as follows with 1 : M cardinality MOVIE (mno, mname, release_yr) and ACTOR(ano, aname)

 Write Ajax program to print Movie details by selecting an Actor's name.

Create table MOVIE and ACTOR as follows with 1 : M cardinality MOVIE (mno, mname, release_yr) and ACTOR(ano, aname) 

 

actor.html

<html>

<head>

<script>

function showHint(str)

{

if (str=="")

{

document.getElementById("mydiv").innerHTML = "";

return;

}

 

if(window.XMLHttpRequest)

{

XHRobj=new XMLHttpRequest();

}

else

{

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

}

 

XHRobj.onreadystatechange = function()

{

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

{

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

}

}

XHRobj.open("GET", "mactor.php?q=" + str, true);

XHRobj.send();

}

</script>

</head>

<body>

<p><b>Actor Details:</b></p>

<form>

<SELECT name="aname" onchange="showHint(this.value)">

<option value="">Select Actor Name</option>

<option value="Ramcharan">Ramcharan</option>

<option value="Allu">Allu</option>

</select>

</form>

<div id="mydiv"><b> Actor info......</b></div>

</body>

</html>

 

mactor.php

<?php

$database="test"; //database name

$q=$_GET["q"];

$con=@mysqli_connect("localhost","root" ,"", "test");

if (!$con)

{

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

}

 

$result=@mysqli_query($con,"SELECT m.mno,m.mname,m.ryear FROM `movie` AS m, `actor` AS a WHERE m.mno=a.mno AND a.aname= '$q'");

 

echo"<table border='1'>";

echo"<tr><th>mno</th><th>mname</th><th>year</th></tr>";

while($row=@mysqli_fetch_array($result))

{

echo"<tr><td>";

echo $row['mno'];

echo"</td><td>";

echo $row['mname'];

echo"</td><td>";

echo $row['ryear'];

echo"</td></tr>";

}

echo"</table>";

@mysqli_close($con);

?>