Skip to content

Instantly share code, notes, and snippets.

@tomschenkjr
Created September 5, 2012 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomschenkjr/3637519 to your computer and use it in GitHub Desktop.
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
<?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);
?>
<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