我正在开发一个网站,该网站允许用户初步选择目的地,然后根据他从复选框中选择的偏好显示四个类别的结果。我无法使用会话变量将下拉列表中选择的选项的值发布到另一个网页。如果不按任何提交按钮,我想将下拉列表中选择的值传递给多个页面。我之前看过很多与此问题相关的帖子,但发现它们都没有用。我的下拉列表代码如下:
的index.php
<div class="dropdownstay">
<select name="city" class="option3" id="dropdown">
<option value="1" id="lhr" style="font-size:20px; font-family:Monotype Corsiva;" >Lahore</option>
<option value="2" id="dub" style="font-size:20px; font-family:Monotype Corsiva;">Dubai </option>
<option value="3" id="new" style="font-size:20px; font-family:Monotype Corsiva;">Newyork</option>
<option value="4" id="can"style="font-size:20px; font-family:Monotype Corsiva;">Canberra</option>
<option value="5" id="kl" style="font-size:20px; font-family:Monotype Corsiva;">Kuala Lampur</option>
<br>
</select>
</form>
<?php
session_start();
if(isset($_POST['city']))
$selected_city = $_POST['city'];
?>
<!--end for drop down -->
</div>
</div>
</li>
</ul>
</div>
<div class="reservation">
<ul>
<li class="span1_of_1">
<h5>What you want in hotel?</h5>
<br>
<form action="checkbox_value.php" method="post">
<section title="preferences">
<input type="checkbox" value="is_pool" id="pool" name="check_list[]" checked />
<text style="font-size:20px; font-family: Times New Roman;"> Pool </text>
<br/>
<input type="checkbox" value="is_gym" id="gym" name="check_list[]" checked />
<text style="font-size:20px; font-family: Times New Roman;"> Gym </text>
<br/>
<input type="checkbox" value="is_beach" id="beach" name="check_list[]" />
<text style="font-size:20px; font-family: Times New Roman;"> Beach </text>
<br/>
<input type="checkbox" value="is_spa" id="spa" name="check_list[]" />
<text style="font-size:20px; font-family: Times New Roman;"> Spa </text>
<br/>
<input type="checkbox" value="is_wifi" id="wifi" name="check_list[]" checked />
<text style="font-size:20px; font-family: Times New Roman;"> Wifi </text>
<br/>
<input type="checkbox" value="is_familyoriented" id="family" name="check_list[]"/>
<text style="font-size:20px; font-family: Times New Roman;"> Family </text>
<br/>
<input type="checkbox" value="is_economical" id="economical" name="check_list[]" />
<text style="font-size:20px; font-family: Times New Roman;"> Economical </text>
<br>
<br>
<br>
<br>
</section>
<div>
<input type="submit" name="submit" value="Submit" style="color: orange;" />
</div>
<?php include 'checkbox_value.php';?>
</form>
</li>
<!--
检索每个类别的数据的代码是&#34; checkbox_value.php&#34;。我想访问变量&#34; city&#34;的值。在这个页面上共有4页。
Checkbox_value.php
<?php
class MyDB extends SQLite3
{
function __construct()
{
$this->open('mytrip.db');
}
}
$db = new MyDB();
if(!$db){
echo $db->lastErrorMsg();
} else {
}
$hotelOptions = array('is_pool', 'is_gym', 'is_spa', 'is_wifi', 'is_beach', 'is_familyoriented', 'is_economical');
$countOptions = array(
'is_pool' => 'pool_count',
'is_gym' => 'gym_count',
'is_spa' => 'spa_count',
'is_wifi' => 'wifi_count',
'is_beach' => 'beach_count',
'is_familyoriented' => 'family_count',
'is_economical' => 'econo_count',
);
//$cities = array(1 => 'Dubai');
if (isset($_POST['submit'])) {
// $selected_city= $_POST['city'];
if (!empty($_POST['check_list']) && is_array($_POST['check_list'])) {
$profpic = "images/Yellow.jpg";
echo "<p> Destination: ".$selected_city ."</p>";
// Counting number of checked checkboxes.
$checked_count = count($_POST['check_list']);
echo "You have selected following ".$checked_count." option(s): <br/>";
// Loop to store and display values of individual checked checkbox.
$where = '';
$order = '';
foreach($_POST['check_list'] as $selected) {
echo "<p>".$selected ."</p>";
if (array_search($selected, $hotelOptions) !== false) {
$where .= " AND {$selected} = 1";
$order .= " {$countOptions[$selected]} DESC,";
}
}
$where = substr($where, 5, strlen($where));
$order = substr($order, 0, strlen($order) - 1);
//echo "<p>".$where ."</p>";
//echo "<p>".$order ."</p>";
session_start();
$id=$_SESSION['Id'];
$city=$_SESSION['selected_city'];
if (isset($city)) {
$sql = "SELECT hotel_name FROM ".$city." WHERE ".$where." ORDER BY ".$order.";";
// echo "<p>".$sql ."</p>";
$ret = $db->query($sql);
session_start();
$id=$_SESSION['Id'];
$ar= array();
$i=0;
while($row = $ret->fetchArray(SQLITE3_ASSOC) ){
echo "<p> <br /></p>\n";
echo "\n". $row['hotel_name'] . "\n";
$ar[$i]= $row['hotel_name'];
$i++;
}
if (is_array($ar))
{
foreach ($ar as $value)
{
echo "<p> Array is " .$value. "<p>";
$sql= "INSERT INTO Search (Id, History)
VALUES ('$id','$value')";
$ret = $db->query($sql);
}
}
}
} else {
echo "<b>Please Select Atleast One Option.</b>";
}
$db->close();
}
?>
<html>
<head>
<style type="text/css">
body {
background-image: url('<?php echo $profpic;?>');
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
</body>
</html>
如何传递下拉列表中选择的值,并且能够在多个页面上访问它而无需使用会话变量提交它?