2つの異なるデータベーステーブルによって作成された2つのドロップダウンメニューを作成しました。私はまた、メニューから何かを選んだ後に押すボタンを作成しました。私は何をしたいですか(しかし私はできません)は、選択された項目を画面に印刷することです。私が今までに書いたコードの下には:ドロップダウンメニューで選択した項目をエコーします
<?php
require_once('assets/index.php');
$result1 = $conn->query("select * from partenze");
$result2 = $conn->query("select * from arrivi");
echo "<html>";echo "<body>";echo "<form action='index.php'>"; echo "Select your Departure: <select name='p_id'>";
while ($row1 = $result1->fetch_assoc()) {
unset($pid, $pname);
$pid = $row1['p_id'];
$plocalita = $row1['p_localita'];
echo '<option value="'.$pid.'">'.$plocalita.'</option>';}
echo "</select><br>";echo "Select your Arrival: <select name='a_id'>";
while ($row2 = $result2->fetch_assoc()) {
unset($aid, $aname);
$aid = $row2['a_id'];
$alocalita = $row2['a_localita'];
echo '<option value="'.$aid.'">'.$alocalita.'</option>';}
echo "</select>";
echo "<input type='submit' name='submit' value='Get Selected Values' />"; echo "</form>";
if(isset($_POST['submit'])){
$selected_val1 = $_POST['p_id']; // Storing Selected Value In Variable
$selected_val2 = $_POST['a_id']; // Storing Selected Value In Variable
echo "You have selected :" .$selected_val1. " and " .$selected_val2; // Displaying Selected Value
}
echo "</body>";echo "</html>";
?>
からの要求を取得するには、フォームで
method=post
を指定する必要がありますオプション。= $オプション。 –[PHPのドロップダウンリストで選択された値を印刷する方法、または選択した値を印刷する方法](https://stackoverflow.com/questions/34516869/how-to-print-the-value-that-ドロップダウンリストの中でドロップダウンリストに表示されます –
基本的に純粋な 'PHP'では' JavaScript1とこれを組み合わせる必要があります。 – Sand