Slip 23 - B) 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).

Solution:

<html>
<head>
<script type="text/javascript">
function display(a_name)
{
// alert("hi");
var ob=false;
ob=new XMLHttpRequest();
ob.onreadystatechange=function()
{
if(ob.readyState==4 && ob.status==200)
document.getElementById("place").innerHTML=ob.responseText;
}
ob.open("GET","slip_14.php?a_name="+a_name,true);
ob.send();
}
</script>
</head>
<body>
Select Actor Name :
<select name="a_name" onchange="display(this.value)">
<option value="">select actor</option>
<option value="Swapnil Joshi">Swapnil Joshi</option>
<option value="Sachit">Sachit</option>
</select>
<div id="place"></div>
</body>
</html>

Php file :

<?php
$a_name = $_GET['a_name'];
$con = mysql_connect("localhost","root","");
$d = mysql_select_db("bca_programs",$con);
$q = mysql_query("select movie.m_no,m_name,r_year from movie,actor_slip_14 where a_name='$a_name' && actor_slip_14.m_no=movie.m_no"); //echo $q;
echo "<table border=1>";
echo "<tr><th>Movie No</th><th>Movie Name</th><th>Release Year</th></tr>";
while($row = mysql_fetch_array($q))
{
echo "";
echo "".$row[0]."";
echo "".$row[1]."";
echo "".$row[2]."";
echo "";
}
echo "</table>";
?>

Post a Comment

0 Comments