根据我的单选按钮选择显示mysql表结果

根据我的单选按钮选择显示mysql表结果

问题描述:

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.

我的radiobuttons为, p>

  selection1:
field1&lt  ; input type =“radio”name =“field1”value =“field1”/&gt; 
field2&lt; input type =“radio”name =“field2”value =“field2”/&gt; 
field3&lt; input type =“radio  “name =”field3“value =”field3“/&gt; 
 
selection2:
type1&lt; input type =”radio“name =”type1“value =”type1“/&gt; 
type2&lt; input type =”radio“  name =“type2”value =“type2”/&gt; 
type3&lt; input type =“radio”name =“type3”value =“type3”/&gt; 
  code>  pre> 
 
  
 
 
  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 
  code>  pre> 
 
 

如果用户选择“field1” code>和“type1” code>它应该将结果显示为10,如果用户选择“field2” code>和“type3” code>它应该显示60,我该如何在 php code>,任何想法?,即使是小想法也欢迎。 p> div>

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