Hey Guys... I am trying to retrieve data from mysql db based on option selected from select tag ( drop down list )
This is my html code
<html>
<head>
<script>
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
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>
</head>
<body>
<form>
<select name="staff" onchange="showUser(this.value)">
<option value="">Select Staff</option>
<option value="Ms.Shakthi">Ms.Shakthi</option>
<option value="Ms.Priya">Ms.Priya</option>
</select>
</form>
<br>
<div id="txtHint"><b>Person info will be listed here.</b></div>
</body>
</html>
Getuser.php code
<?php
$q = intval($_GET['q']);
$con = mysqli_connect('localhost','willy','12345','test');
if (!$con)
{
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"test");
$sql="SELECT * FROM test WHERE Staff = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<table border='1'>
<tr>
<th>Name</th>
<th>Class</th>
<th>Syllabus</th>
<th>Motivated</th>
<th>Time</th>
<th>Doubts</th>
<th>Marking</th>
<th>Interesting</th>
<th>Methods</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['Class'] . "</td>";
echo "<td>" . $row['Syllabus'] . "</td>";
echo "<td>" . $row['Motivated'] . "</td>";
echo "<td>" . $row['Time'] . "</td>";
echo "<td>" . $row['Doubts'] . "</td>";
echo "<td>" . $row['Marking'] . "</td>";
echo "<td>" . $row['Interesting'] . "</td>";
echo "<td>" . $row['Methods'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
When I select an option, the data isn't retrieved
1 回答
intval
获取一个整数,但$ _GET ['q']是一个字符串 . 所以我客人所需要的是:编辑:我建议您使用开发工具(Chrome中的F12或Firefox中的firebug)来调试您的程序 . 和
echo $variable
或使用PHP中的任何调试工具 .