dslf46995 2016-02-17 09:21
浏览 15

使用DB检查复选框

i've got n checkboxes. If one of them is checked user id and checkbox id are goin to DB . How can i save checkbox clicked after page reloading. Now i'm facing the problem in the cycle

for ($i = 0; $i < count($arr[3])); $i++){   // $arr - array containing user id and ckeckbox id    
          $active = "";
       if ($arr[3][$i]['id'] != ""){
          $active = "active" // class for active checkbox       

}
$checkbox .= "<div class="check_ '.$active.'"></div>";
}

for example if i've got 3 checkboxes and clicking on 1 and 3,an array will be like {1,3,NULL} instead of {1,NULL,3}. i think ckeckbox id should be equal to checkbox number

  • 写回答

2条回答 默认 最新

  • doutou6803 2016-02-17 10:39
    关注

    solved like this

    for ($j=0; $j< count($array[3]); $j++){
            $mailing_list_id = $mailing_lists[3][$j]['id'];          
            $m_active = "";
            if(!empty($clicked[3])){ 
                for ($i=0;$i<count($result[3]);$i++){                
                    if ($array[3][$j]['id'] == $clicked[3][$i]['id_usr_mailing_lists']){
                        $m_active = "active";
                    } 
                }  
        $checkbox .= "<div class="check_ '.$active.'"></div>";
    
    
            }
    

    where $arr contains all checkboxes and clicked contains clicked checkboxes

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序