Saturday, 18 April 2015

Ajax-onChange -onClick-Event -With-PHP (same time on single page)

(1)write code for  "filterdownload.php":

<html>
<head>

<script>
function ajax_post(){
    // Create our XMLHttpRequest object
    var hr = new XMLHttpRequest();
    // Create some variables we need to send to our PHP file
    var url = "displaynotes1previous.php";
    var fn = document.getElementById("coursename").value;

    var en = document.getElementById("semseter").value;








    var vars = "coursename="+fn+"&semseter="+en;

    hr.open("POST", url, true);
    // Set content type header information for sending url encoded variables in the request
    hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    // Access the onreadystatechange event for the XMLHttpRequest object
    hr.onreadystatechange = function() {
   if(hr.readyState == 4 && hr.status == 200) {
   var return_data = hr.responseText;
document.getElementById("status").innerHTML = return_data;
   }
    }
    // Send the data to PHP now... and wait for response to update the status div
    hr.send(vars); // Actually execute the request
    document.getElementById("status").innerHTML = "processing...";
}


function ajax_disp(){
    // Create our XMLHttpRequest object
    var hr = new XMLHttpRequest();
    // Create some variables we need to send to our PHP file
    var url = "displaynotes1.php";
    var fn = document.getElementById("coursename").value;

    var en = document.getElementById("semseter").value;

var pn = document.getElementById("subject").value;







    var vars = "coursename="+fn+"&semseter="+en+"&subject="+pn;

    hr.open("POST", url, true);
    // Set content type header information for sending url encoded variables in the request
    hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    // Access the onreadystatechange event for the XMLHttpRequest object
    hr.onreadystatechange = function() {
   if(hr.readyState == 4 && hr.status == 200) {
   var return_data = hr.responseText;
document.getElementById("status").innerHTML = return_data;
   }
    }
    // Send the data to PHP now... and wait for response to update the status div
    hr.send(vars); // Actually execute the request
    document.getElementById("status").innerHTML = "processing...";
}


</script>

</head>
<body>
<span style="color:#000;">Select Course Name : -</span>
<select  name=coursename  id="coursename"    >
<?php




$con = mysql_connect('localhost', 'root', '');
mysql_select_db("itexam", $con);

$sql="select * from subject group by coursename ";

$result=mysql_query($sql) or die(mysql_error());



while ($row=mysql_fetch_array($result))

{

echo '<option  value="'.$row['coursename'].'">';


echo $row['coursename'];


echo '<option>';




}

?>
</select>

<span style="color:#000;">Select Semester : -</span>
<select  name=semseter  id="semseter"   onChange="ajax_post();">

<?php




$con=mysql_connect("localhost","root","");

mysql_select_db("itexam",$con);

$sql="select * from subject  group by semseter  ";

$result=mysql_query($sql) or die(mysql_error());



while ($row=mysql_fetch_array($result))

{

echo '<option  value="'.$row['semseter'].'">';


echo $row['semseter'];


echo '<option>';




}

?>
</select>

<!------>

<div id="status">

</div>







<input align="middle" name="myBtn" type="submit" value="Submit Data"    onclick="ajax_disp();">








<br /><br /><br /><br />





<?php

ob_flush();

?>

</div>


</center>

</body>
</html>

(2)write code for   "displaynotes1previous.php" :

<html>
<head>


</head>
<body>
<?php
$coursename=$_POST['coursename'];

$semseter=$_POST['semseter'];

?>

Subject  <select  name="subject"   id="subject">
<?php
$con = mysql_connect('localhost', 'root', '');
mysql_select_db("itexam", $con);
$sql="select  subject  from subject where coursename='$coursename' AND  semseter='$semseter'";
$result=mysql_query($sql) or die(mysql_error());
while ($row=mysql_fetch_array($result))
{
echo '<option  value="'.$row['subject'].'">';
echo $row['subject'];
echo '<option>';
}
?>
</select>


</td></tr>
<tr>
<td>

</tr>
<div id="status1"></div>
</body>
</html>

(3)write code for  "displaynotes1.php file":


<?php


ob_start();

?>

<?php


$coursename=$_POST['coursename'];


$semester=$_POST['semseter'];


$subject=$_POST['subject'];


echo '<h3>';

echo '<table border=0>';

echo '<tr> <td>';
echo "CourseName&nbsp;=".$coursename;

echo '</td> <td>&nbsp;&nbsp;&nbsp;</td>';

echo '<td>';

echo "Semester&nbsp;=".$semester;

echo '</td></tr>';
echo '</table>';

echo '</h3>';

//$con=mysql_connect("localhost","root","");

$con = mysql_connect('localhost', 'root', '');
mysql_select_db("itexam", $con);

//mysql_select_db("itexam",$con);


$sql="select * from   notes    where   coursename='$coursename'    AND semester='$semester'  AND subject='$subject' order by subject";


$result=mysql_query($sql) or die(mysql_error());

echo '<h4>';
echo '<table border=0>';

echo '<tr><td><h2>Subject Name </h2></td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td><h2>Unit </h2></td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td> <td> <h2>Download Link</h2></td></tr>';



while($row=mysql_fetch_array($result))
{
echo ' <tr><td>"'.$row['subject'].'" </td><td>&nbsp;</td><td>"'.$row['unit'].'" </td><td>&nbsp;</td>
<td>
<button ><a href=../proudct_images/'.$row['file'].'>
Download file</a></button> </td></tr>';
}
echo '</table>';
?>
<?php
$sql1="select * from   downloadall    where   coursename='$coursename'    AND semester='$semester'   order by subject";
$result1=mysql_query($sql1) or die(mysql_error());
while($row1=mysql_fetch_array($result1))
{
echo ' <tr>
<td>
<button ><a href=../uploadall/'.$row1['file'].'>
Download All Notes</a></button> </td></tr>';

}
?>
<?php

ob_flush();

?>



No comments:

Post a Comment