データベースのテーブルからドロップダウンリストを作成します。ユーザーが選択したドロップリストで選択したアイテムを取得しようとしています。そのアイテムに関連する詳細情報を取得するためにデータベースにクエリを実行できます。選択したアイテムをドロップダウンリストで使用して、PHPのアイテムを公開するにはどうすればよいですか?
<html>
<head></head>
<body>
<br>
<table id ="topnav" width="1100" border="0" align="center">
<tr>
<td colspan="2" style="background-color:#FFA500;">
<h1><table border="0">
<tr>
<th colspan="6"><img src ="../_images/Eu_flags.jpg" border="0" align="top" width="1100" height="180" />
</th>
</tr>
<table></h1>
</td>
</tr>
<tr valign="top">
<td style="background-color:#FFD700;width:150px;text-align:top;">
<b>Menu</b><br />
Select the state<br>
See rank of Universities<br />
Other information
</td>
<td style="background-color:#eeeeee;height:100px;width:940px;text-align:top;">
<?php
$con = mysql_connect("localhost","root","pasword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$result = mysql_query("SELECT lnamestate FROM state");
while($row = mysql_fetch_array($result))
{
$lnamestate_id = $lnamestate['id'];
$row_lnamestate=$row['lnamestate'];
$row_block .= '<OPTION value="'.lnamestate_id.'">'.$row_lnamestate.'</OPTION>';
}
mysql_close($con);
?>
<label for="row">Select state</label>
<select name="lnamestateID"><?php echo $row_block; ?></select>
</td>
</tr>
<tr>
<td colspan="2" style="background-color:#FFA500;text-align:center;">
</td>
</tr>
</table>
</table>
</body>
</html>
あるフィールドが別のフィールドの値を決定するようにフォームを連結する方法の例がたくさんあります。これはajax用ですが、コンセプトはまだ保持されています:http://stackoverflow.com/questions/6495657/display-data-from-two-mysql-tables-by-getting-values-from-drop-down-list- using-p –