嗨,謝謝你看我。我完全是使用PHP運行MySQL select語句的新手段。話雖如此,我設法運行一個SELECT語句來填充一個下拉列表......和另一個SELECT語句來填充一個HTML表格。 (這是一個角色扮演遊戲)將下拉列表值傳遞給同一頁上的另一個SELECT語句
但是,這是我where3卡住...
我想對於下拉列表選擇的值是「WHERE racename =」,在第二個SELECT語句值填充該表使得只返回一行而不是所有的數據。
這裏的頁面:http://www.gamehermit.com/racechoice.php
這裏是我到目前爲止的代碼:
<?php
// Make a MySQL Connection
mysql_connect("localhost", "db_username", "password") or die(mysql_error());
mysql_select_db("db_name") or die(mysql_error());
$query="SELECT * FROM Races";
$result = mysql_query($query);
echo "<select name=racename>";
while($nt=mysql_fetch_array($result))
{
if ($nt[racename]==$_POST["racename"])
$selected="selected";
else
$selected="";
echo "<option ".$selected."value=$nt[racename]>$nt[racename]</option>";
}
echo "</select>";
echo "<br />";
// Get all the data from the "Race" table and create table
$result2 = mysql_query("SELECT * FROM Races")
or die(mysql_error());
echo "<table border='1'>";
echo "<tr> <th>Race Name</th> <th>Might Modifier</th> <th>Valor Modifier</th> <th>Deftness
Modifier</th> <th>Insight Modifier</th> <th>Dweomer Modifier</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array($result2)) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['racename'];
echo "</td><td>";
echo $row['modmight'];
echo "</td><td>";
echo $row['modvalor'];
echo "</td><td>";
echo $row['moddeftness'];
echo "</td><td>";
echo $row['modinsight'];
echo "</td><td>";
echo $row['moddweomer'];
echo "</td></tr>";
}
echo "</table>";
?>
我希望這是簡單...非常感謝:)
〜傑克
[Chained Select Boxes jquery php]可能的重複(http://stackoverflow.com/questions/9724087/chained-select-boxes-jquery-php) – 2012-08-01 14:12:35