douguluan5102 2015-07-16 06:20
浏览 37
已采纳

根据我的单选按钮选择显示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.

  • 写回答

2条回答 默认 最新

  • dtmjqyfz21793 2015-07-16 06:43
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!