[英]Conditional PHP Statements relating to an HTML form
我有一个HTML表单,然后需要在PHP中引用它,以便最终可以筛选数据。 现在,它只是出于测试目的而回显了一些文本。
我使用$ _GET变量获取哪些值等于什么,然后使用if / else语句告诉我是否已检查每个值。
如果我说它仅等于一个值(== .25),则返回false。
但是,如果我添加一个或多个值(== .25或.375或.5),它将返回我需要的值。
我怎样才能只返回一个值就返回true?
<table stlye="width:100%">
<tr>
<td style="width:50%">
<form method="GET">
Tool Diameter: <br>
<input type="checkbox" name="Tool Diameter" value=.25 checked> .25<br>
<input type="checkbox" name="Tool Diameter" value=.375 checked> 3/8<br>
<input type="checkbox" name="Tool Diameter" value=.5 checked> 1/2<br><br>
Brand: <br>
<input type="checkbox" name="Brand" value="Lakeshore Carbide " checked> Lakeshore Carbide<br>
<input type="checkbox" name="Brand" value="AB Tools" checked> AB Tools<br>
<input type="checkbox" name="Brand" value="Helical Tools" checked> Helical Tools<br><br>
Flutes: <br>
<input type="checkbox" name="Flutes" value="2" checked> 2<br>
<input type="checkbox" name="Flutes" value="3" checked> 3<br>
<input type="checkbox" name="Flutes" value="4" checked> 4<br><br>
Tool Material: <br>
<input type="checkbox" name="Material" value="HSS" checked> HSS<br>
<input type="checkbox" name="Material" value="Carbide" checked> Carbide<br>
<input type="checkbox" name="Material" value="Cobalt" checked> Cobalt<br><br>
Coating: <br>
<input type="checkbox" name="Coating" value="Uncoated" checked> Uncoated<br>
<input type="checkbox" name="Coating" value="ZrN" checked> ZrN<br>
<input type="checkbox" name="Coating" value="TiCN" checked> TiCN<br><br>
Tool Type: <br>
<input type="checkbox" name="Type" value="Face Mill" checked> Face Mill<br>
<input type="checkbox" name="Type" value="Flat Endmill" checked> Flat Endmill<br>
<input type="checkbox" name="Type" value="Ball Endmill" checked> Ball Endmill<br>
<br><button>Filter</button><br>
</form>
</td>
<td style="width:50%">
<style type="text/css">
td
{
padding:0 50px 0 50px;
}
</style>
<?php
//while (true){
if ($_GET['Tool Diameter'] == .375) {
echo 'test = true';
}
else {
echo "false";
}
?>
</td>
</tr>
</table>
将值转换为字符串,例如
<input type="checkbox" name="Tool Diameter" value=".375" checked> .375<br>
然后检查
if ($_GET['Tool Diameter'] == ".375"){
enter code here
}
第一个错误
值必须用括号括起来value=".25"
第二错误
名称必须是唯一的,因此数组$_GET['Tool Diameter']
只有一个值,因此$_GET['Tool Diameter']
应该有一个包含结果数组的槽,所以可以说
$_GET['Dimensions'] = [
'Dimension 1' => '.25',
'Dimension 2' => '.375',
'Dimension 3' => '.5'
];
然后分别参考每个
尝试这个
<input type="checkbox" name="Tool Diameter[]" value=".25" checked> .25<br>
<input type="checkbox" name="Tool Diameter[]" value=".375" checked> 3/8<br>
<input type="checkbox" name="Tool Diameter[]" value=".5" checked> 1/2<br><br>
.....
<?php
// for checking the condition 'atleast 1 ' should be checked
if(sizeof($_GET['Tool Diameter']) >=1){
echo 'test = true';
}
else {
echo "test = false";
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.