Created
September 5, 2012 14:32
-
-
Save tomschenkjr/3637519 to your computer and use it in GitHub Desktop.
Create a dropdown box to query data and display in table on HTML page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$q=$_GET['q']; | |
$con = mysql_connect('mysql.tomschenkjr.net', 'tsjr_visitor', 'tsjr_visitor_password'); | |
if(!$con){ | |
die('Could not connect: ' . mysql_error()); | |
} | |
mysql_select_db("tsjr_sandy", $con); | |
$sql="SELECT * FROM tsjr_sandy.workforceTransitions WHERE id = '.$q.'"; | |
$result = mysql_query($sql); | |
echo "<table border='1'> | |
<tr> | |
<th>Top 5 Sectors</th> | |
</tr>"; | |
// Tried to only display this, doesn't work. | |
// echo $sql . "<br />"; | |
// echo $result . "<br />"; | |
// echo $q . "<br />"; | |
while($row = mysql_fetch_array($result)){ | |
echo "<tr>"; | |
echo "<td>" . $row['TopSector1'] . "</td>"; | |
echo "<td>" . $row['TopSector2'] . "</td>"; | |
echo "<td>" . $row['TopSector3'] . "</td>"; | |
echo "<td>" . $row['TopSector4'] . "</td>"; | |
echo "<td>" . $row['TopSector5'] . "</td>"; | |
} | |
echo "</table>"; | |
mysql_close($con); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript"> | |
function getMajor(str){ | |
if (str="") { | |
document.getElementById("majorInfo").innerHTML=""; | |
return; | |
} | |
if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari | |
xmlhttp=new XMLHttpRequest(); | |
} | |
else{ // code for IE6 | |
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); | |
} | |
xmlhttp.onreadystatechange=function(){ | |
if (xml.readyState==4 && xmlhttp.status=200){ | |
document.getElementById("majorInfo").innerHTML=xmlhttp.responseText; | |
} | |
} | |
xmlhttp.open("GET","getuser.php",true); | |
xmlhttp.send(); | |
} | |
</script> | |
</head> | |
<body> | |
<form> | |
<select name="major" onchange="getMajor(this.value)"> | |
<option value="">Select a major...</option> | |
<option value="1">Agriculture, Food, and Natural Resources</option> | |
<option value="2">Architecture and Construction</option> | |
<option value="3">Arts, AV and Communication</option> | |
<option value="4">Business, Management and Administration</option> | |
<option value="5">Education and Training</option> | |
<option value="6">Finance</option> | |
<option value="7">Government and Public Administration</option> | |
<option value="8">Health Sciences</option> | |
<option value="9">Hospitality and Tourism</option> | |
<option value="10">Human Services</option> | |
<option value="11">Information Technology</option> | |
<option value="12">Law, Public Safety, and Security</option> | |
<option value="13">Manufacturing</option> | |
<option value="14">Marketing, Sales, and Service</option> | |
<option value="15">STEM</option> | |
<option value="16">Transportation, Distribution and Logistics</option> | |
<option value="17">College Parallel</option> | |
</select> | |
</form> | |
<br /> | |
<div id="majorInfo"><b>Information about majors will be listed here</b></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment