单击提交按钮时,我想从表单中查询所有选定的选项,但这不会发生。它仅考虑最后一个选项(EU)。如果有人可以帮忙。谢谢!
<form name="filter_form" method="POST" action="display_data.php">
Select a country:
<select name="country">
<option name="country" value="AL">All</option>
<option name="country" value="AU">Austria</option>
<option name="country" value="BE">Belgium</option>
</select>
Select Type:
<select name="ASS">
<option name="ASS" value="all">All</option>
<option name="ASS" value="think">Think Tanks</option>
<option name="ASS" value="network">Networks</option>
<option name="ASS" value="NGO">NGOs</option>
</select>
Select EU Attitude:
<select name="EU">
<option name="EU" value="all">All</option>
<option name="EU" value="PRO">PRO EU</option>
</select>
<input type="submit" name="btn_submit" value="Submit Filter" />
</form>
我的PHP代码:
<?php
if(isset($_POST['country']))
{
switch($_POST['country'])
{
case 'BE' : $countryName = 'Belgium';
break;
case 'AU' : $countryName = 'Austria';
break;
case 'BU' : $countryName = 'Bulgaria';
break;
default : $countryName = '';
break;
}
$where = '';
if($countryName != '')
{
$where = "WHERE Country='".$countryName."'";
}
}
if(isset($_POST['ASS']))
{
switch($_POST['ASS'])
{
case 'think' : $type = 'Think Tank';
break;
case 'network' : $type = 'Network';
break;
case 'NGO' : $type = 'NGO';
break;
default : $type = '';
break;
}
$where = '';
if($type != '')
{
if(!empty($type)){
$where .= " AND Type='".$type."'";
} else {
$where = "WHERE Type='".$type."'";
}
}
}
if(isset($_POST['EU']))
{
switch($_POST['EU'])
{
case 'PRO' : $eus = 'PRO EU';
break;
case 'REFORM' : $eus = 'Reform EU';
break;
case 'ANTI' : $eus = 'Eurosceptic';
break;
default : $eus = '';
break;
}
$where = '';
if($eus != '')
{
if((!empty($countryName)) || (!empty($type))){
$where .= " AND Attitude='".$eus."'";
} else {
$where = "WHERE Attitude='".$eus."'";
}
}
$query = mysql_query("SELECT * FROM think ".$where."");
}
?>
答案 0 :(得分:1)
您继续重置$ where:
$where = '';
在顶部设置一次,然后让它运行。
答案 1 :(得分:1)
在每个块中重置where子句$where =''
。
从ASS
和EU
块中删除它,并将其放在脚本的开头,仅将变量初始化为空字符串。