dsfb20227 2015-06-11 07:59 采纳率: 0%
浏览 35

css选中复选框

I want to display the checkbox in while loop and nned to apply the CSS based on $status value.If status=open in database open should be checked and vice versa for status='Close' .I have CSS for each and every row based on id.I created random id in PHP variable $a.

Now This is working only for status='open' which is checked in if condition.

     $a=0;
         while($sfet=mysql_fetch_assoc($sql1))
         {
              echo ('<style>

      .ck-button'.$a.' {
       margin:0px;
       background-color:#EFEFEF;
       border-radius:4px;
      border:1px solid #D0D0D0;
      overflow:auto;
       float:left;
       }

    .ck-button'.$a.' #label'.$a.' {
    float:left;
    width:4.0em;
    }
    .ck-button'.$a.' #label'.$a.' #span'.$a.' {
     text-align:center;
     padding:3px 0px;
      display:block; 
     border-radius:4px;
      }

    .ck-button'.$a.' #label'.$a.' input {
     position:absolute;
     top:-20px;
     }
    input#o1'.$a.':checked + #span'.$a.' {
    background-color: green;
     color: #fff;
   }
  input#o2'.$a.':checked + #span'.$a.' {
   background-color: red;
  color: #fff; 
   }
  input#o3'.$a.':checked + #span'.$a.' {
  background-color: orange;
   color: #fff;
   }

 .ck-button'.$a.' #label'.$a.':hover #o1'.$a.' + #span'.$a.' {
 background-color:green;
 }
 .ck-button'.$a.' #label'.$a.':hover #o2'.$a.' + #span'.$a.' {
  background-color:red;  
 }
 .ck-button'.$a.' #label'.$a.':hover #o3'.$a.' + #span'.$a.' {
  background-color:orange;
  }
   </style>'); 
           $title=$sfet['title'];
           $c_name=$sfet['c_name'];
           $e_first_name=$sfet['e_first_name'];
           $status=$sfet['status'];
           $req_id=$sfet['req_id'];
           $e_id=$sfet['e_id'];
           echo '<tr><td><a href="broadcast_detail.php?req_id='.$req_id.'" class="astext">'.$title.'</a></td><td>'.$c_name.'</td><td>'.$e_first_name.'</td>';
            $count="select * from resume where e_id='$e_id' and req_id='$req_id'";
            $count1=mysql_query($count);
            $num=mysql_num_rows($count1);
           echo '<td>'.$num.'</td>';
           if($status=='Open')
           {
           echo"<td><div class='ck-button".$a."'><label id='label".$a."'><input type='radio' name='sta_choice".$a."' id='o1".$a."' onclick=demo('Open',".$req_id."); value='Open' checked><span id='span".$a."'>Open</span></label></div>";
            echo"<div class='ck-button".$a."'><label id='label".$a."'><input type='radio' name='sta_choice".$a."' id='o2".$a."' value='Close' onclick=demo('Close',".$req_id.");><span id='span".$a."'>Close</span></label></div>";
             echo"<div class='ck-button".$a."'><label id='label".$a."'><input type='radio' name='sta_choice".$a."' id='o3".$a."' value='Hold' onclick=demo('Hold',".$req_id.");><span id='span".$a."'>Hold</span></label></div></td><br><br>";

           }
           else if($status=='close'){


             echo"<td><div class='ck-button".$a."'><label id='label".$a."'><input type='radio' name='sta_choice".$a."' id='o1".$a."' onclick=demo('Open',".$req_id."); value='Open'><span id='span".$a."'>Open</span></label></div>";
              echo"<div class='ck-button".$a."'><label id='label".$a."'><input type='radio' name='sta_choice".$a."' id='o2".$a."' value='Close' onclick=demo('Close',".$req_id.");><span id='span".$a."' checked>Close</span></label></div>";
               echo"<div class='ck-button".$a."'><label id='label".$a."'><input type='radio' name='sta_choice".$a."' id='o3".$a."' value='Hold' onclick=demo('Hold',".$req_id.");><span id='span".$a."'>Hold</span></label></div></td><br><br>";

           }
  $a++;
  }
  • 写回答

1条回答 默认 最新

  • douzhi3454 2015-06-11 08:06
    关注

    It seems to me that the if statement is faulty, it echo's the exact same thing, thus not resulting in any changes if the database option changes.

    Also Open is with a capital letter, and close is not.

    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵