aboutsummaryrefslogtreecommitdiff
path: root/ajax/database
diff options
context:
space:
mode:
Diffstat (limited to 'ajax/database')
-rw-r--r--ajax/database/New Text Document.txt0
-rw-r--r--ajax/database/getuser.php38
-rw-r--r--ajax/database/index.htm20
-rw-r--r--ajax/database/selectuser.js40
4 files changed, 98 insertions, 0 deletions
diff --git a/ajax/database/New Text Document.txt b/ajax/database/New Text Document.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/ajax/database/New Text Document.txt
diff --git a/ajax/database/getuser.php b/ajax/database/getuser.php
new file mode 100644
index 0000000..bf6e677
--- /dev/null
+++ b/ajax/database/getuser.php
@@ -0,0 +1,38 @@
+<?php
+$q=$_GET["q"];
+
+$con = mysql_connect('localhost', 'peter', 'abc123');
+if (!$con)
+ {
+ die('Could not connect: ' . mysql_error());
+ }
+
+mysql_select_db("ajax_demo", $con);
+
+$sql="SELECT * FROM user WHERE id = '".$q."'";
+
+$result = mysql_query($sql);
+
+echo "<table border='1'>
+<tr>
+<th>Firstname</th>
+<th>Lastname</th>
+<th>Age</th>
+<th>Hometown</th>
+<th>Job</th>
+</tr>";
+
+while($row = mysql_fetch_array($result))
+ {
+ echo "<tr>";
+ echo "<td>" . $row['FirstName'] . "</td>";
+ echo "<td>" . $row['LastName'] . "</td>";
+ echo "<td>" . $row['Age'] . "</td>";
+ echo "<td>" . $row['Hometown'] . "</td>";
+ echo "<td>" . $row['Job'] . "</td>";
+ echo "</tr>";
+ }
+echo "</table>";
+
+mysql_close($con);
+?> \ No newline at end of file
diff --git a/ajax/database/index.htm b/ajax/database/index.htm
new file mode 100644
index 0000000..98b0009
--- /dev/null
+++ b/ajax/database/index.htm
@@ -0,0 +1,20 @@
+<html>
+<head>
+<script type="text/javascript" src="selectuser.js"></script>
+</head>
+<body>
+
+<form>
+Select a User:
+<select name="users" onchange="showUser(this.value)">
+<option value="1">Peter Griffin</option>
+<option value="2">Lois Griffin</option>
+<option value="3">Glenn Quagmire</option>
+<option value="4">Joseph Swanson</option>
+</select>
+</form>
+<br />
+<div id="txtHint"><b>Person info will be listed here.</b></div>
+
+</body>
+</html> \ No newline at end of file
diff --git a/ajax/database/selectuser.js b/ajax/database/selectuser.js
new file mode 100644
index 0000000..a91721e
--- /dev/null
+++ b/ajax/database/selectuser.js
@@ -0,0 +1,40 @@
+var xmlhttp;
+
+function showUser(str)
+{
+xmlhttp=GetXmlHttpObject();
+if (xmlhttp==null)
+ {
+ alert ("Browser does not support HTTP Request");
+ return;
+ }
+var url="getuser.php";
+url=url+"?q="+str;
+url=url+"&sid="+Math.random();
+xmlhttp.onreadystatechange=stateChanged;
+xmlhttp.open("GET",url,true);
+xmlhttp.send(null);
+}
+
+function stateChanged()
+{
+if (xmlhttp.readyState==4)
+{
+document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
+}
+}
+
+function GetXmlHttpObject()
+{
+if (window.XMLHttpRequest)
+ {
+ // code for IE7+, Firefox, Chrome, Opera, Safari
+ return new XMLHttpRequest();
+ }
+if (window.ActiveXObject)
+ {
+ // code for IE6, IE5
+ return new ActiveXObject("Microsoft.XMLHTTP");
+ }
+return null;
+} \ No newline at end of file