こんにちは、私と一緒にこれを見てくれてありがとう。PHPを使用してMySQLselectステートメントを実行するのはまったく初めてです。そうは言っても、私はSELECTステートメントを実行してドロップダウンリストにデータを入力し、別のSELECTステートメントを実行してHTMLテーブルにデータを入力することができました。(これはロールプレイングゲーム用です)
しかし、これは私が立ち往生している場所3です...
ドロップダウンで選択された値を、テーブルに入力する2番目のselectステートメントの「WHEREracename =」値にして、すべてのデータではなく1つの行のみが返されるようにします。
これがページです: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>";
?>
これが簡単だといいのですが...どうもありがとうございました:)
〜ジャック