Php 根据我的单选按钮选择显示我的sql表结果
我的单选按钮是Php 根据我的单选按钮选择显示我的sql表结果,php,html,mysql,database,radio-button,Php,Html,Mysql,Database,Radio Button,我的单选按钮是 selection1: field1<input type="radio" name="field1" value="field1"/> field2<input type="radio" name="field2" value="field2"/> field3<input type="radio" name="field3" value="field3"/> selection2: type1<input type="radio"
selection1:
field1<input type="radio" name="field1" value="field1"/>
field2<input type="radio" name="field2" value="field2"/>
field3<input type="radio" name="field3" value="field3"/>
selection2:
type1<input type="radio" name="type1" value="type1"/>
type2<input type="radio" name="type2" value="type2"/>
type3<input type="radio" name="type3" value="type3"/>
如果用户选择
“field1”
和“type1”
则结果应显示为10,如果用户选择“field2”
和“type3”
则应显示60,我如何在php
中执行此操作,有什么想法吗?即使是很小的想法也受欢迎 首先,您必须为不同的单选按钮组使用不同的名称
public Datatable GetRecord(string fieldName, string type)
{
//Call Store Procedure and Pass fieldName , Type as param
}
In you Store Procedure:
@FieldParam nvarchar(max),
@FieldType nvarchar(max)
as
begin
select * from test where Field = @FieldParam and Type = @FieldType
end
接下来,如果您想在HTML表单标记中使用它,您可以执行如下操作
<form action='test.php' method='post'>
selection1:
field1<input type="radio" name="field" value="field1"/>
field2<input type="radio" name="field" value="field2"/>
field3<input type="radio" name="field" value="field3"/>
selection2:
type1<input type="radio" name="type" value="type1"/>
type2<input type="radio" name="type" value="type2"/>
type3<input type="radio" name="type" value="type3"/>
<input type='submit'>
</form>
这对你有用是无线基站吗?有点宽泛。您在sql、php等方面有什么问题。?您的表单元素缺少名称和值。我无法获取数据库记录,这取决于所选的两个单选按钮。这正是我要查找的。还有一个疑问,如果我的数据库中还有result2、result3,代码会如何变化?结果2和结果3是什么意思??你的意思是,如果我选择field1和type1,我会得到结果1、结果2和结果3???1-$sql=“从测试中选择result1、result2、result3,其中field='$field'和type='$type';2-不返回$result[result]而使用此打印($result)。。谢谢你的回复,这对我很有帮助。
<form action='test.php' method='post'>
selection1:
field1<input type="radio" name="field" value="field1"/>
field2<input type="radio" name="field" value="field2"/>
field3<input type="radio" name="field" value="field3"/>
selection2:
type1<input type="radio" name="type" value="type1"/>
type2<input type="radio" name="type" value="type2"/>
type3<input type="radio" name="type" value="type3"/>
<input type='submit'>
</form>
function get_value($type,$field)
{
$sql="select result from test where field='$field' and type='$type'";
$query=mysql_query($sql) or die(mysql_error());
$result=mysql_fetch_array($query);
return $result[result];
}
$field=$_POST['field'];
$type=$_POST['type'];
echo get_value($type,$field);