我的选择标签会给我玩家的名字,然后查询将在后面运行,然后显示结果。我已经完成了一些教程,但找不到答案。我在这里添加我的 html 和 php 文件代码。
//html and script player.html file
<script>
<script type="text/javascript" src="jque`enter code here`ry.js">
$(document).ready(function() {
$('#player').on('change', function() {
var qString = '{name: ' + $('#player option:selected').text() + '}';
$.post('getplayer.php', qString, processResponse);
// $('#resultsGoHere').html(qString);
});
function processResponse(data) {
$('#resultsGoHere').html(data);
}
});
</script>
<form id="myForm">
<select id="player" name="player" onchange="showPlayer(this.value)">
<option value = "None">Choose One</option>
<option value = "Zidane">Zidane</option>
<option value = "Messi">Messi</option>
<option value = "Cristiano Ronaldo">Cristiano Ronaldo</option>
<option value = "Bergkemp">Bergkemp</option>
</select></br></br>
<!--<input type="submit" name="submit" value="Submit" />-->
</form>
//php part getplayer.php file
<?php
$name = $_POST['theDropdown'];
echo "$name";
/*
$db = mysql_connect("localhost","root","root");
mysql_select_db("football");
$select = "SELECT * FROM players";
$result = mysql_query($select) or die(mysql_error());
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Name</th>
<th>Position</th>
<th>Club</th>
<th>Nationality</th>
<th>Date of birth</th>
</tr>";
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<th>" . $row['id'] . "</td>";
echo "<th>" . $row['name'] . "</td>";
echo "<th>" . $row['pos'] . "</td>";
echo "<th>" . $row['club'] . "</td>";
echo "<th>" . $row['nationality'] . "</td>";
echo "<th>" . $row['dob'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($db);
*/
?>