-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmidterm.txt
68 lines (60 loc) · 1.61 KB
/
midterm.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<html>
<head>
<script>
function showData(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("data").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","mid2.php?dept_name="+str,true);
xmlhttp.send();
}
}
</script>
<?php
//make connection
mysql_connect('localhost','root','Qwerty999');
//select db
mysql_select_db('employees');
$sql = "SELECT * FROM departments";
$records = mysql_query($sql);
?>
<html>
<head>
<meta charset="UTF-8">
<title>Midterm</title>
</head>
<body>
<h2>PHP AJAX QUERY DATABASE</h2>
<form>
<select name="department" onchange="document.getElementById('id2').submit();">
<?php
echo "<option>Select</option>";
while ($departments = mysql_fetch_array($records))
{
echo "<option value=".$departments['dept_no'].">".$departments['dept_name']."</option>";
#send dept_no, only show dept_name
}
echo "<td>".$departments['dept_no']."</td>";
?>
</select>
</form>
<br>
<div id="id2"><b>Data will be shown here...</b></div>
</body>
</html>
<?php
include 'mid2.php';
?>