我制作了一個下拉列表,它從數據庫中獲取數據(名稱)并顯示在下拉列表的選項中?,F在我試圖從列表中獲取該選定名稱的整行,并希望將每個數據保存到一個變量中以供進一步使用。誰能指導我...這是我在 PHP/MySQL 中的第一個項目,請幫助我...這是我的下拉列表代碼:<form action="sel2.php" method="post"> Player: <select name="data[]" multiple> <option disabled selected>-- Select Player --</option> <?php $records = mysqli_query($con, "SELECT * From bat"); // Use select query here while($data = mysqli_fetch_array($records)) { echo "<option value='". $data['name'] ."'>" .$data['name'] ."</option>"; // displaying data in option menu } echo "</select>"; echo "<input type='submit' name='submit' value='Submit' />";echo "</form>";?>我已經設法獲取名稱并將其存儲到一個變量中:<?php if(isset($_POST['submit'])){ if(!empty($_POST['data'])) { foreach($_POST['data'] as $selected){ $curdata = $selected; } } else { echo 'Please select the value.'; } }?>我設法在另一個頁面 (sel.php) 中得到了回應:<!DOCTYPE html><html><head> <title>PHP Retrieve Data</title> <?php include "connection.php"; include "sel2.php";// Using database connection file here ?></head><body><center><?phpecho $curdata, "<br>" , $batq;?></center></body></html>但是我如何存儲該特定行的所有值,例如:$id = //id of selected name from dropdown list$age = //age of selected name from dropdown list等等等等
如何獲取與在下拉列表中選擇的列關聯的整行?
胡子哥哥
2023-05-11 16:50:09