gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 07:34:16 26 4
gpt4 key购买 nike

我的单选按钮为,

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"/>

我在数据库表“test”中预定义了值

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中做到这一点,有什么想法吗?,即使是很小的想法也是受欢迎的。

最佳答案

首先您必须为不同的单选按钮组使用不同的名称

接下来,如果你想在 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);

这对你有用

关于php - 根据我的单选按钮选择显示 mysql 表结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31446617/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com