gpt4 book ai didi

PHP MySQL 设置selectpicker选中多个

转载 作者:行者123 更新时间:2023-11-30 00:23:33 26 4
gpt4 key购买 nike

我需要有关 Bootstrap 选择器集成的 php 脚本的帮助

我有用于显示 selectpicker 多个值的 php 脚本

<select id="skill" name="skill" class="selectpicker" multiple data-size="5" data-selected-text-format="count">
<?php
$skills = mysql_query("SELECT skill_id, skill_name FROM skill",$conn);
while($r_skills = mysql_fetch_assoc($skills)){
echo '<option value="'.$r_skills['skill_id'].'">'.$r_skills['skill_name'].'</option>
';
}
?>
</select>

在我的另一张 table 上,我有用户和技能ID,技能ID内容:1,2,3

我已经将它分解为每个值,如下所示:

$q = ("SELECT nik, skill_id FROM dosen WHERE nik = '".$nik."'",$conn);
while($row_dosen = mysql_fetch_assoc($q)){

$pieces = explode(",", $row_dosen['skill_id']);

for($i = 0; $i < count($pieces) ; $i++){

$pp = mysql_query("SELECT skill_id, skill_name FROM skill WHERE skill_id = '".$pieces[$i]."'",$conn);

while($p = mysql_fetch_assoc($pp)){
$var_each = $p['skill_id'];

}
}
}

问题是:我如何为我的多个选择器选项设置默认选定值,以使它们被选为表上的用户数据?

谢谢。我们将不胜感激您的帮助:)

最佳答案

怎么样:

<select id="skill" name="skill" class="selectpicker" multiple data-size="5" data-selected-text-format="count">
<?php
$skills = mysql_query("SELECT skill_id, skill_name FROM skill",$conn);
while($r_skills = mysql_fetch_assoc($skills)){
echo '<option value="'.$r_skills['skill_id'].'"';
if ($r_skills['skill_id'] == '1337 codingz')
echo ' selected';
echo '>'.$r_skills['skill_name'].'</option>';
}
?>
</select>

关于PHP MySQL 设置selectpicker选中多个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23052203/

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