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.

    评论

报告相同问题?

悬赏问题

  • ¥20 用vivado写数字逻辑实验报告撰写,FPGA实验
  • ¥15 为什么shp文件会有这种小方块?
  • ¥15 ecplise在连接数据库时显示加载驱动成功但是数据库连接失败
  • ¥15 visionmaster启动失败,提示为“机器不满足授权而被禁用”
  • ¥15 IDEA中圈复杂度如何具体设置
  • ¥50 labview采集不了数据
  • ¥15 Multisim红外倒车雷达仿真中距离问题
  • ¥15 请上面代码做什么处理或什么混淆
  • ¥15 英雄联盟自定义房间置顶
  • ¥15 W5500网线插上无反应