Database: 650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7F/ED/wKiom1cxmqaTUhj0AAA33CaMLRs331.png "title=" Database Picture "alt=" Wkiom1cxmqatuhj0aaa33camlrs331.png "/>
Front Page: choseform.php
<script type= "Text/javascript" >
function Showuser (str) {
var xmlhttp;
if (str== "")
{
document.getElementById ("Txthint"). innerhtml= "";
Return
}
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 ("Txthint"). Innerhtml=xmlhttp.responsetext;
}
}
Xmlhttp.open ("GET", "getuser.php?q=" +str,true);
Xmlhttp.send ();
}
</script>
<body>
<form>
Select a User:
<select name= "Users" onchange= "Showuser (this.value)" >
<option value= "0" >please choose</option>
<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>
<div id= "Txthint" > Customer information will be listed here ...</div>
</body>
Background files: getuser.php
<?php
$q =$_get["Q"];
$mysql _server_name= "localhost"; Database server name
$mysql _username= "root"; Connect to database user name
$mysql _password= "cxst789"; Connect Database Password
$mysql _database= "User"; The name of the database
Connecting to a database
$con =mysql_connect ($mysql _server_name, $mysql _username,
$mysql _password);
if (! $con)
{
Die (' Could not connect: '. Mysql_error ());
}
mysql_select_db ("User", $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);
?>
This article is from the "Phpajax request" blog, so be sure to keep this source http://15129824665.blog.51cto.com/10510385/1771839
Phpajax request MySQL Database