I have my radiobuttons as,
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"/>
i have predefined values in my database 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
if user selects "field1"
and "type1"
it should display the result as 10, if user selects "field2"
and "type3"
it should display 60, how can i do it in php
, any ideas?, even small thought are welcome.
first you have to use different name for different radio Button group
next if you want to use it in HTML form tag you can do some thing like below
<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>
in PHP code you should use a function like this
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);
this will work for you
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