如何在php中添加带有启用或禁用格式的复选框?
两个数据库表 1-customer_表 customer_id customer_group 1 1,2,3 2 - 3 1,5,3,4 客户id客户组 1 1,2,3 2 - 3 1,5,3,4 第二张桌子 2-群 group_id group_name 1 A 2 B 3 C 4 D 5 E 组\u id组\u名称 1A 2 B 3 C 4d 5 E 我想在带有复选框的客户表中为添加组创建代码 当我们在客户id 1中添加组时,复选框显示为1,2,3,4,5,其中1,2,3显示为选中或禁用复选框,其余仅显示为复选框如何在php中添加带有启用或禁用格式的复选框?,php,mysql,Php,Mysql,两个数据库表 1-customer_表 customer_id customer_group 1 1,2,3 2 - 3 1,5,3,4 客户id客户组 1 1,2,3 2
if($row['customer\u group']='')
{
$res=“从grp\U表中选择grp\U id、grp\U名称”;
$result1=mysql\u查询($res);
而($row1=mysql\u fetch\u数组($result1))
{
echo“.”.$row1['grp_name'];
回声“
”;
}
}
其他的
{
$res=“从组表中选择grp\U id、grp\U名称”;
$result1=mysql\u查询($res);
$lst_rp=explode(',',$row['customer_group']);
foreach($lst\u rp作为$rp\u id)
{
而($row1=mysql\u fetch\u数组($result1))
{
echo$rp_id;
如果($row1[grp\u id]='$rp\u id')
{
echo”“。$row1['sim\u grp\u name'];
回声“
”;
}
其他的
{
echo“.”.$row1['grp_name'];
回声“
”;
}
}
}
}
?>
但我无法达到我的最终结果 您可能想显示复选框。您需要将第4行更改为disabled=“disabled”
1 while($row1=mysql\u fetch\u数组($result1)){
2 echo$rp_id;
3如果($row1[grp\u id]='$rp\u id'){
4 echo“。$row1['sim_grp_name'];
回音“
”;}else{
echo“.”.$row1['grp_name'];
回声“
”;
}
如果您再次查看您的问题,您会如何描述它?您遇到的路障在哪里?在_数组中使用,而不是(==)。我必须离开,否则我将为您编写代码。创建一个customer_group字段explode is by的数组,然后在应用2组表上的循环时,检查每个组id是否与_数组中相同(身份证,你的姓氏)
if($row['customer_group']=='')
{
$res = "SELECT grp_id, grp_name FROM grp_table";
$result1 = mysql_query($res);
while($row1 = mysql_fetch_array($result1))
{
echo "<input name='group[]' id='group[]' type='checkbox' value='$row1[grp_id]' />"."". $row1['grp_name']." " ;
echo "<br>";
}
}
else
{
$res = "SELECT grp_id, grp_name FROM group_table";
$result1 = mysql_query($res);
$lst_rp = explode(',', $row['customer_group']);
foreach($lst_rp as $rp_id)
{
while($row1 = mysql_fetch_array($result1))
{
echo $rp_id;
if($row1[grp_id]=='$rp_id')
{
echo "<input name='group[]' id='group[]' checked='checked' type='checkbox' value='$row1[grp_id]' disabled />"."". $row1['sim_grp_name']." " ;
echo "<br>";
}
else
{
echo "<input name='group[]' id='group[]' type='checkbox' value='$row1[grp_id]' />"."". $row1['grp_name']." " ;
echo "<br>";
}
}
}
}
1 while($row1 = mysql_fetch_array($result1)) {
2 echo $rp_id;
3 if($row1[grp_id]=='$rp_id') {
4 echo "<input name='group[]' id='group[]' checked='checked' type='checkbox' value='$row1[grp_id]' disabled="disabled" />"."". $row1['sim_grp_name']." " ;
echo "<br>"; } else {
echo "<input name='group[]' id='group[]' type='checkbox' value='$row1[grp_id]' />"."". $row1['grp_name']." " ;
echo "<br>";
}