我如何从一个选择的选项值中获取多个值。 这里有一个例子,
<html>
<form method="post" action="#">
<select name="retrive_destination">
<?php while($row = mysql_fetch_assoc($result)){
$destinationID = $row['destinationID'];
$destination_place = $row['destination_place'];
echo '<option value="'.$destinationID.'">'.$destination_place.'</option>
?>
<input type="submit">
</select>
</form>
</html>
当我提交表单时,当用户在下一步中选择一个选项时我需要这两个值,我如何从一个选项值中获取“$destinationID”和“$destination_place”这两个值。谢谢你们的欢呼。
最佳答案
组合两个值然后在服务器端分解它们
<html>
<form method="post" action="#">
<select name="retrive_destination">
<?php while($row = mysql_fetch_assoc($result)){
$destinationID = $row['destinationID'];
$destination_place = $row['destination_place'];
echo '<option value="'.$destinationID."_".htmlentities($destination_place).'">'.$destination_place.'</option>
?>
<input type="submit">
</select>
</form>
</html>
PHP 服务器端
$value= $_REQUEST['retrive_destination'];
$explode=explode("_",$value,2);
$destinationID =$explode[0];
$destination_place =$explode[1];
关于php - 从一个选择选项值中获取多个值。 PHP HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22102197/