Thanks in advance for any help.
I currently have a dropdown that pulls "sport" from database.
I need help figuring out how to pull from MULTIPLE drop downs.
Ideally, I'd like 4-5 dropdown boxes that act like a filter.
If none are selected the entire table is listed and results are updated as dropdowns are selected.
<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();
}
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","getuser2.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="sport" onchange="showUser(this.value)">
<option value="">Select a sport:</option>
<option value="Hockey">Hockey</option>
<option value="Soccer">Soccer</option>
<option value="Basketball">Basketball</option>
<option value="Football">Football</option>
<option value="Baseball">Baseball</option>
<option value="Other">Lax & Other Sports</option>
</select>
</form>
<br>
<div id="txtHint"><b>Sport info will be here.</b></div>
<form>
<select name="state" onchange="showUser(this.value)">
<option value="">Select a State:</option>
<option value="NY">NY</option>
<option value="NV">NV</option>
<option value="GA">GA</option>
<option value="NH">NH</option>
<option value="OH">OH</option>
<option value="CT">CT</option>
</select>
</form>
<br>
<div id="txtHint"><b>State info will be here.</b></div>
</body>
</html>
getuser.php:
<?php
$q=$_GET["q"];
$con = mysql_connect("localhost","nystockt_steve","eli91363");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("nystockt_test", $con);
$sql="SELECT * FROM tourney WHERE sport = '".$q."'";
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>Sport</th>
<th>State</th>
<th>Male</th>
<th>Female</th>
<th>Indoor</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['sport'] . "</td>";
echo "<td>" . $row['state'] . "</td>";
echo "<td>" . $row['male'] . "</td>";
echo "<td>" . $row['female'] . "</td>";
echo "<td>" . $row['indoor'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
I currently have a dropdown that pulls "sport" from database.
I need help figuring out how to pull from MULTIPLE drop downs.
Ideally, I'd like 4-5 dropdown boxes that act like a filter.
If none are selected the entire table is listed and results are updated as dropdowns are selected.
<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();
}
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","getuser2.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="sport" onchange="showUser(this.value)">
<option value="">Select a sport:</option>
<option value="Hockey">Hockey</option>
<option value="Soccer">Soccer</option>
<option value="Basketball">Basketball</option>
<option value="Football">Football</option>
<option value="Baseball">Baseball</option>
<option value="Other">Lax & Other Sports</option>
</select>
</form>
<br>
<div id="txtHint"><b>Sport info will be here.</b></div>
<form>
<select name="state" onchange="showUser(this.value)">
<option value="">Select a State:</option>
<option value="NY">NY</option>
<option value="NV">NV</option>
<option value="GA">GA</option>
<option value="NH">NH</option>
<option value="OH">OH</option>
<option value="CT">CT</option>
</select>
</form>
<br>
<div id="txtHint"><b>State info will be here.</b></div>
</body>
</html>
getuser.php:
<?php
$q=$_GET["q"];
$con = mysql_connect("localhost","nystockt_steve","eli91363");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("nystockt_test", $con);
$sql="SELECT * FROM tourney WHERE sport = '".$q."'";
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>Sport</th>
<th>State</th>
<th>Male</th>
<th>Female</th>
<th>Indoor</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['sport'] . "</td>";
echo "<td>" . $row['state'] . "</td>";
echo "<td>" . $row['male'] . "</td>";
echo "<td>" . $row['female'] . "</td>";
echo "<td>" . $row['indoor'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>