gpt4 book ai didi

php - 如何根据行值 1、2、5、6 恢复选中和未选中的复选框

转载 作者:行者123 更新时间:2023-11-29 19:44:26 24 4
gpt4 key购买 nike

我有一个表,其中有一列名为“角色”,以这种方式指示人员的角色“1,3,6..”,以及其他具有此角色名称的表。任何 id 都对应一个角色。

我正在尝试将所有角色打印为复选框,并检查此人是否具有其中任何角色。

我正在尝试内爆和爆炸,但没有结果,你能指导我吗?

<input type="checkbox" name="roles[]" value="'.($row['id']).'" >'.($row['name']).'</input>

最佳答案

试试这个

    $user_id = $_REQUEST['user_id'];
$user_role = array();
$result = mysql_query("SELECT role_id FROM user_role where user_id = '$user_id' ");
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
$user_role[] = explode(',' $row['role_id']);
}// end while

$getRoleList = mysql_query("select role_id, role_name from role ");
while ($roleRow = mysql_fetch_array($getRoleList, MYSQL_BOTH)) {
if(in_array($roleRow['role_id'], $user_role)){
echo '<input type="checkbox" name="roles[]" value="'.($roleRow['role_id']).'" checked="checked">'.($roleRow['role_name']);
}else{
echo '<input type="checkbox" name="roles[]" value="'.($roleRow['role_id']).'" >'.($roleRow['role_name']);
}// end if
}// end while

关于php - 如何根据行值 1、2、5、6 恢复选中和未选中的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41131322/

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