Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7171337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:23:41+00:00 2026-05-28T15:23:41+00:00

My output is like this:- when i print_r ($aResultData) Array ( [0] => Array

  • 0

My output is like this:-
when i print_r ($aResultData)

Array ( [0] => Array ( [parent] => SK336 [child] => CP ) [1] => Array ( [parent] => SK336 [child] => PES ) [2] => Array ( [parent] => SK995 [child] => MS ) [3] => Array ( [parent] => SK995 [child] => LSW ) [4] => Array ( [parent] => SK995 [child] => GES ) [5] => Array ( [parent] => SK995 [child] => RSW ) )

Now I want to show this data into a checkbox in php.

            parent  child
checkbox    SK336   CP
checkbox    SK336   PES
checkbox    SK995   MS
checkbox    SK995   LSW
checkbox    SK995   GES
checkbox    SK995   RSW

and a submit button

and after submit checkbox (it depends what i am selected) and finally it stores in to another database what i can do ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:23:42+00:00Added an answer on May 28, 2026 at 3:23 pm

    You can do like:

    $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>';
    }
    

    Hope this helps

    EDIT:

    If you want to check all child checkbox if parent is selected then you need to c=use jQuery and also had to change PHP code:

    PHP Code:

    $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) {
               echo '<div style="margin-left:15px;"><input type="checkbox" name="childs[]" value="'.$child.'" id="childs_'.$child.'" class="child_'.$parent.'"/>
               <label for="childs_'.$child.'">'.$child.'</label></div>';
         }
         echo '</div>';
    }
    

    JS CODE:

    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);
        });
    });
    

    NEW EDIT :

    If you want to uncheck the parent when a child is unchecked and check the parent when all the child are selected you can use this:

    PHP CODE:

    $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>';
    }
    

    JS CODE:

    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");
           }
     }
    

    This thing works 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array like this (output from print_r ): Array ( [price] =>
In this C# code snippet, DateTime.Now.Month.ToString() returns 7 as output. I would like to
Hey guys I have an array like this print_r($grouparray); Array ( [0] => Array
You've probably familiar with this output from print_r: Hierarchy Object ( [parent:private] => Hierarchy
I'm trying something like this Output.py print Hello Input.py greeting = raw_input(Give me the
Suppose you have output like this: Word1 Word2 Word3 Word4 Where the number of
I have a SQL Server 2005 output like this: Date | Result | Sum
Often when writing PHP I'll have it output some HTML like this - echo
The output of /proc/net/dev on Linux looks like this: Inter-| Receive | Transmit face
I recently used the <<- operator to output a multi-line string, like this: <<-form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.