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 (标签-python)
  • ¥15 第一个已完成,求第二个做法
  • ¥20 搭建awx,试了很多版本都有错
  • ¥15 java corba的客户端该如何指定使用本地某个固定IP去连接服务端?
  • ¥15 activiti工作流问题,求解答
  • ¥15 有人写过RPA后台管理系统么?
  • ¥15 Bioage计算生物学年龄
  • ¥20 如何将FPGA Alveo U50恢复原来出厂设置哇?
  • ¥50 cocos2d-x lua 在mac上接入lua protobuf?
  • ¥15 es 7.17.20版本生成时间戳