scrappedcola
Posting Whiz in Training
227 posts since Dec 2009
Reputation Points: 27
Solved Threads: 45
main.php
<html>
<head>
<script type="text/javascript">
function showUser(str)
{
var url="getuser.php";
url=url+"?q="+str;
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==0 || xmlhttp.readyState==1 || xmlhttp.readyState==2 || xmlhttp.readyState==3 || xmlhttp.readyState==4)
{
document.getElementById("txtHint").innerHTML="Loading...";
}
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
Select a User:
<select name="users" onchange="showUser(this.value)">
<option value="1">A</option>
<option value="2">B/option>
<option value="3">C</option>
<option value="4">D</option>
</select>
</form>
<br />
<div id="txtHint">
<b>Person info will be listed here.</b>
</div>
</body>
</html>
getuser.php
<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'username', 'password');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("[dbname]", $con);
$sql="SELECT * FROM [table_name] WHERE login = '".$q."'";
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Maths</th>
<th>Physics</th>
<th>Chemistry</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['sname'] . "</td>";
echo "<td>" . $row['fname'] . "</td>";
echo "<td>" . $row['maths'] . "</td>";
echo "<td>" . $row['physics'] . "</td>";
echo "<td>" . $row['chemistry'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>