我需要通过bootstrap selectpicker集成帮助我的php脚本
我有用于show 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>
在我的另一张桌子上我有user和skill_id,对于skill_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'];
}
}
}
问题是:如何为我的多个selectpicker选项设置默认选择值,使它们在桌面上被选为我的用户数据?
谢谢。 帮助将不胜感激:)
答案 0 :(得分:0)
如下:
<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>