我有一个带有选择字段的表单:
<select class="indexSearchLocationList" name="locationList">
<option value="allLocations">Anywhere in London</option>
<option value="barking_and_dagenham">Barking and Dagenham </option>
<option value="barnet">Barnet</option>
我想尝试做的是,如果用户选择分配选项(在伦敦的任何地方),那么我需要使用它来选择所有查询数据库下面是我当前拥有的php但是如何指定该特定选项选择:
$choosenLocation = $_POST['locationList'];
答案 0 :(得分:0)
你期待类似的东西,
$choosenLocation = $_POST['locationList'];
if(isset($choosenLocation) && $choosenLocation == 'allLocations'){
$query = "select * from TABLE ";
//based on the mysqli_ or PDO you execute
//fetch the row and display accordingly
}else{
$query = "select * from TABLE WHERE condition='your condition here' " ;
}
答案 1 :(得分:0)
我认为可能是
if(isset($_POST['locationList']) & $_POST['locationList']=='allLocations')
{
$query = "select * from TABLE ";
//based on the mysqli_ or PDO you execute
//fetch the row and display accordingly
}
答案 2 :(得分:0)
试试这个,如果不符合您的要求,请将您的要求简要添加为评论。
$choosenLocation = $_POST['locationList'];
if($choosenLocation == 'allLocations')
{
$query = "select * from TABLE ";
}
else
{
$query = "select * from TABLE WHERE condition="any_condition";
}