根据我的单选按钮选择显示我的 sql table 结果
displaying my sql table result based on my radiobutton selection
我有我的单选按钮,
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"/>
我的数据库中有预定义值 table "test" as
field1 type1 10
field1 type2 20
field1 type3 30
field2 type1 30
field2 type2 50
field2 type3 60
field3 type1 80
field3 type2 90
field3 type3 100
如果用户选择"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>
在 PHP 代码中你应该使用这样的函数
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);
这对你有用
我有我的单选按钮,
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"/>
我的数据库中有预定义值 table "test" as
field1 type1 10
field1 type2 20
field1 type3 30
field2 type1 30
field2 type2 50
field2 type3 60
field3 type1 80
field3 type2 90
field3 type3 100
如果用户选择"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>
在 PHP 代码中你应该使用这样的函数
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);
这对你有用