我有 hotel_id 和 hotel_name
的表酒店和
我有一个链接
<a href = "#" id="hotel">Post</a>
当我点击上面的链接时,我想生成一个带下拉的弹出框(其中选项值= hotel_id,显示的文本是hotel_name),当用户从下拉菜单中选择酒店时,我如何获得php中的选项值。
提前致谢!!!
答案 0 :(得分:0)
:
<a href="#" id="hotel" onclick="return openHotelPopup(hotelnames.php);">Post</a>
在Javascript中:
function openHotelPopup(url)
{
newwindow=window.open(url,'name','height=200,width=150');
}
in hotelnames.php
$con = mysql_connect("localhost","test","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM table_hotels");
echo '<form name="myform" method="post"><select name="hotels" onchange="myform.submit();">';
while($row = mysql_fetch_array($result))
{
echo '<option value="'.$row['hotel_id'].'>'.$row['hotel_name'].'</option>';
}
echo "</select></form>";
mysql_close($con);
现在,您的弹出式下拉菜单将如下所示:
<form name="myform" method="post">
<select name="hotels" onchange="myform.submit();">
<option value="1">Vol</option>
<option value="2">Sa</option>
<option value="3">Op</option>
<option value="4">Au</option>
</select>
</form>
当您从此下拉菜单中选择任何一个选项时,您将使用以下PHP代码在PHP中检索该值。
<?php
print_r($_REQUEST['hotels'])
?>
输出将是:
Array ( [hotels] => 1 ); (if you would have selected Vol in drop down menu)