两个数据库表
1-CUSTOMER_TABLE
customer_id customer_group 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
我想用复选框创建在customer表中添加组的代码。
当我们在客户ID 1中添加组时,复选框显示1,2,3,4,5其中1,2,3显示复选框,选中或禁用,仅作为复选框休息....
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>";
}
}
}
}
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>";
}
}
}
}
但我无法达到我的最终结果。
答案 0 :(得分:0)
您可能希望显示该复选框。您需要将第4行更改为disabled =“disabled”
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>";
}