这是我的PHP代码:
<?php
echo " <select data-live-search='true' data-live-search-style='startsWith' class='selectpicker' id='locName'>";
$stmt = $conn->prepare('SELECT LocationName From arealistmain');
$stmt->execute();
{
echo "<option>Select Location</option>";
}
$stmt->execute();
while($row = $stmt->fetch()){
echo "<option>" .$row['LocationName'] . "</option>";
}
echo "</select>";
?>
刷新网页后,我需要保留位置。
答案 0 :(得分:0)
PHP是无状态的,因此您不能使用POST或GET发送变量(尽管可以使用cURL)。 使用会话或Cookie
//On page 1
$_SESSION['location'] = $location;
//On page 2
$location= $_SESSION['location'];
在第2页上,当您执行循环时,请检查该值
while($row = $stmt->fetch())
$selected = '';
if($row['LocationName'] == $location){
$selected = 'selected';
}
echo "<option $selected>$row[LocationName]</option>";
}
完成后,您可能想取消设置$ _SESSION变量:
unset($_SESSION['location'])