Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在复选框中显示数据_Php_Zend Framework - Fatal编程技术网

Php 如何在复选框中显示数据

Php 如何在复选框中显示数据,php,zend-framework,Php,Zend Framework,我的输出如下:- 当我打印($aResultData) 现在我想在php中将这些数据显示在一个复选框中 parent child checkbox SK336 CP checkbox SK336 PES checkbox SK995 MS checkbox SK995 LSW checkbox SK995 GES checkbox SK995 RSW 还有一个提交按钮 在“提交”复选框(这取决于我选择了什么)

我的输出如下:- 当我打印($aResultData)

现在我想在php中将这些数据显示在一个复选框中

            parent  child
checkbox    SK336   CP
checkbox    SK336   PES
checkbox    SK995   MS
checkbox    SK995   LSW
checkbox    SK995   GES
checkbox    SK995   RSW
还有一个提交按钮

在“提交”复选框(这取决于我选择了什么)之后,最后它会将我可以做的事情存储到另一个数据库中。

您可以像这样做:

$parents = array();
$childs = array();
foreach ($aResultData as $aResultDataValue) {
      $parents [$aResultDataValue['parent']] = $aResultDataValue['parent'];
      $childs [$aResultDataValue['parent']][] = $aResultDataValue['child'];
}

foreach ($parents as $parent) {
     echo '<div>';
     echo '<div><input type="checkbox" name="parents[]" value="'.$parent.'" id="parents_'.$parent.'"/>
     <label for="parents_'.$parent.'">'.$parent.'</label></div>';
     foreach ($childs[$parent] as $child) {
            echo '<div style="margin-left:15px;"><input type="checkbox" name="childs[]" value="'.$child.'" id="childs_'.$child.'"/>
            <label for="childs_'.$child.'">'.$child.'</label></div>';
     }
    echo '</div>';
}
新编辑:

如果要在取消选中子项时取消选中父项,并在选中所有子项时选中父项,则可以使用以下选项:

PHP代码:

$parents = array();
$childs = array();
foreach ($aResultData as $aResultDataValue) {
     $parents [$aResultDataValue['parent']] = $aResultDataValue['parent'];
    $childs [$aResultDataValue['parent']][] = $aResultDataValue['child'];
}

foreach ($parents as $parent) {
     echo '<div>';
     $parent_value = "'$parent'";
     echo '<div><input type="checkbox" name="parents[]" value="'.$parent.'" id="'.$parent.'" class="parentCheck"/>
     <label for="parents_'.$parent.'">'.$parent.'</label></div>';
     foreach ($childs[$parent] as $child) {
           $child_value = "'$child'";
               echo '<div style="margin-left:15px;"><input type="checkbox" name="childs[]" value="'.$child.'" id="childs_'.$child.'" class="child_'.$parent.'" onclick="checkParent('.$parent_value.','.$child_value.');"/>
              <label for="childs_'.$child.'">'.$child.'</label></div>';
     }
     echo '</div>';
}
这东西有用:)

你可以这样做:

$parents = array();
$childs = array();
foreach ($aResultData as $aResultDataValue) {
      $parents [$aResultDataValue['parent']] = $aResultDataValue['parent'];
      $childs [$aResultDataValue['parent']][] = $aResultDataValue['child'];
}

foreach ($parents as $parent) {
     echo '<div>';
     echo '<div><input type="checkbox" name="parents[]" value="'.$parent.'" id="parents_'.$parent.'"/>
     <label for="parents_'.$parent.'">'.$parent.'</label></div>';
     foreach ($childs[$parent] as $child) {
            echo '<div style="margin-left:15px;"><input type="checkbox" name="childs[]" value="'.$child.'" id="childs_'.$child.'"/>
            <label for="childs_'.$child.'">'.$child.'</label></div>';
     }
    echo '</div>';
}
新编辑:

如果要在取消选中子项时取消选中父项,并在选中所有子项时选中父项,则可以使用以下选项:

PHP代码:

$parents = array();
$childs = array();
foreach ($aResultData as $aResultDataValue) {
     $parents [$aResultDataValue['parent']] = $aResultDataValue['parent'];
    $childs [$aResultDataValue['parent']][] = $aResultDataValue['child'];
}

foreach ($parents as $parent) {
     echo '<div>';
     $parent_value = "'$parent'";
     echo '<div><input type="checkbox" name="parents[]" value="'.$parent.'" id="'.$parent.'" class="parentCheck"/>
     <label for="parents_'.$parent.'">'.$parent.'</label></div>';
     foreach ($childs[$parent] as $child) {
           $child_value = "'$child'";
               echo '<div style="margin-left:15px;"><input type="checkbox" name="childs[]" value="'.$child.'" id="childs_'.$child.'" class="child_'.$parent.'" onclick="checkParent('.$parent_value.','.$child_value.');"/>
              <label for="childs_'.$child.'">'.$child.'</label></div>';
     }
     echo '</div>';
}

这件事很管用:)

你能更具体地说明要显示哪些数据吗?你想显示所有的父母和孩子,还是只显示一个?还是有点混乱。您想同时显示父项和子项还是只显示一个复选框并显示父项和子项?您能否更具体地说明要显示哪些数据?您想显示所有父项和子项还是仅显示一个?仍然存在混淆。您是否希望同时选中父项和子项或jsut一个复选框并显示父项和子项???)但如果我选择父项,我也希望选择全部查看我的此问题:)这对我有效谢谢,但我希望在取消选择任何子项时,例如LSW,然后在其父项之后,例如SK995,也自动选择deselect@Sabari+1为一个正确答案和所有编辑。干得好@Sabari:)现在我想把所有这些数据插入到tagaccess表中,如果您的from submit方法是post,我可以做什么。您可以将$\u POST['parents']中所有选中的父项作为值数组,也可以将$\u POST['childs']中的子项作为值数组。您可以从这些数组中获取值,并以创建数据库结构的方式将其插入到数据库中。:)完全正确,但如果我选择父级,我还想选择“全部”,请参见我的此问题:)这对我有效,谢谢,但我希望在取消选择任何子级时(例如LSW),然后在其父级之后(例如SK995)也自动执行deselect@Sabari +1 获取正确答案和所有编辑。干得好@Sabari:)现在我想把所有这些数据插入到tagaccess表中,如果您的from submit方法是post,我可以做什么。您可以将$\u POST['parents']中所有选中的父项作为值数组,也可以将$\u POST['childs']中的子项作为值数组。您可以从这些数组中获取值,并以创建db结构的方式将其插入到db中。
$parents = array();
$childs = array();
foreach ($aResultData as $aResultDataValue) {
     $parents [$aResultDataValue['parent']] = $aResultDataValue['parent'];
    $childs [$aResultDataValue['parent']][] = $aResultDataValue['child'];
}

foreach ($parents as $parent) {
     echo '<div>';
     $parent_value = "'$parent'";
     echo '<div><input type="checkbox" name="parents[]" value="'.$parent.'" id="'.$parent.'" class="parentCheck"/>
     <label for="parents_'.$parent.'">'.$parent.'</label></div>';
     foreach ($childs[$parent] as $child) {
           $child_value = "'$child'";
               echo '<div style="margin-left:15px;"><input type="checkbox" name="childs[]" value="'.$child.'" id="childs_'.$child.'" class="child_'.$parent.'" onclick="checkParent('.$parent_value.','.$child_value.');"/>
              <label for="childs_'.$child.'">'.$child.'</label></div>';
     }
     echo '</div>';
}
jQuery(document).ready(function(){
      // add multiple select / deselect functionality
      jQuery(".parentCheck").click(function () {
           var childId = jQuery(this).attr('id');
           jQuery('.child_'+childId).attr('checked', this.checked);
      });
 });
 function checkParent(parentId,childId) {
    if(jQuery(".child_"+parentId).length == $(".child_"+parentId+":checked").length) {
           $('#'+parentId).attr("checked", "checked");
       } else {
           $('#'+parentId).removeAttr("checked");
       }
 }