gpt4 book ai didi

php - 如何处理两个下拉列表值?

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

我默认有三个下拉菜单。第一个下拉列表值将影响第二个和第三个下拉列表的可见性。例如,选择选项一,隐藏第三个下拉列表,显示第二个下拉列表。第二个和第三个下拉列表将保存数据库中同一列的值。

<select class="ui fluid selection dropdown dd" name="category1" id="category1">
<i class="dropdown icon"></i>
<option value="">Which category does this fall into?</option>
<option value="1">Gestures</option>
<option value="2">Etiquette</option>
</select>
<?php if(isset($_POST['category1'])) { $category1 = $_POST['category1']; }?>

<div class="category2" >
<select class="ui fluid selection dropdown dd" name="category2" id="category2" >
<i class="dropdown icon"></i>
<option value="">Be specific...</option>
<option value="1">Friendly gestures</option>
<option value="2">Gestures of respect</option>
<option value="3">Salutes</option>
<option value="4">Celebratory gestures</option>
<option value="5">Finger-counting</option>
<option value="6">Obscene gestures</option>
<option value="7">Taunts</option>
<option value="8">Head motions</option>
<option value="9">Other gestures</option>
</select>
</div>
<?php if(isset($_POST['category2'])) { $category2 = $_POST['category2']; }?>

<div class="category3" style="display:none!important;">
<select class="ui fluid selection dropdown dd" name="category3" id="category3">
<i class="dropdown icon"></i>
<option value="">Be specific...</option>
<option value="10">Greetings</option>
<option value="11">Making payment</option>
<option value="12">Visiting someone's house</option>
<option value="13">Gifts and gift-giving</option>
<option value="14">Table manners</option>
<option value="15">Eating and drinking</option>
<option value="16">Funerals</option>
<option value="17">Bars and restaurants</option>
<option value="18">Driving</option>
<option value="19">Business etiquette</option>
<option value="20">Hierarchy and honoring the elder</option>
</select>
</div>
<?php if(isset($_POST['category3'])) { $category3 = $_POST['category3']; }?>

现在,$category2 和 $category3 代表数据库中的同一列。如果我要进行插入查询,如何确保发布并存储任一下拉值?

mysqli_query($link,"INSERT INTO practices(category1,category2) VALUES('$category1','$category2 or $category3')")

我尝试过这个,并且

<?php if(isset($_POST['category2'])) { $category2 = $_POST['category2']; }?>
<?php if(isset($_POST['category3'])) { $category2 = $_POST['category3']; }?>

这仅适用于其中一个下拉列表,而插入另一个下拉列表时出错。任何帮助将不胜感激

最佳答案

将之前发布的值保存在隐藏字段中,然后使用第二个下拉列表再次发布。

    <div class="category3" style="display:none!important;">


<?php if(isset($_POST['category2']))
{
echo'<select name="pre_category" >
<option selected="selected" value="'.$_POST['category2'].'">'.$_POST['category2'].' </option>
</select>';
} ?>
<select class="ui fluid selection dropdown dd" name="category3" id="category3">
<i class="dropdown icon"></i>
<option value="">Be specific...</option>
<option value="10">Greetings</option>
<option value="11">Making payment</option>
<option value="12">Visiting someone's house</option>
<option value="13">Gifts and gift-giving</option>
<option value="14">Table manners</option>
<option value="15">Eating and drinking</option>
<option value="16">Funerals</option>
<option value="17">Bars and restaurants</option>
<option value="18">Driving</option>
<option value="19">Business etiquette</option>
<option value="20">Hierarchy and honoring the elder</option>
</select>
</div>

现在您可以从 pre_category 中找到值

关于php - 如何处理两个下拉列表值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52913771/

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