单击服务时隐藏和显示活动复选框复选框

uemypmqf  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(420)

PHP

<?php 
//for service 1
$all_activities = "select * from activity join displayserviceactivitymap on activity.activity_id = displayserviceactivitymap.activity_id right  join services on services.service_id = displayserviceactivitymap.service_id";    

$all_activities = $conn->query($all_activities) or die ($conn>error.__LINE__);
$activities = [];

while ($row = $all_activities->fetch_assoc()) {
    $activities[] = $row;
}
$repeated = 'repeated';

foreach ($activities as $act) {
  if($act['servicename'] != $repeated){

    echo '<br><input type="checkbox" name="arr['.$act['service_id'].'][service]" value="'.$act['service_id'].'" id="'.$act['service_id'].'">'.$act['service_id'].$act['servicename'].'<br>';
    $repeated = $act['servicename'];
  }

  if($act['activity_id'] != '')

  echo '<input type="checkbox" name="arr['.$act['service_id'].'][activity][]" value="'.$act['activity_id'].'" id="'.$act['activity_id'].'">'.$act['nameofactivity'].'<br>';
}

?>

我的代码的输出是
所得税
返回
填满
格林威治恒星时
形式
返回
gstr公司
tds公司
应用
退款
这里incometax、gst、tds是服务,其他是服务的相关活动。我想在选中复选框时显示活动,在取消选中复选框时隐藏。

m2xkgtsf

m2xkgtsf1#

为了更好的理解,请尝试运行整个代码

<?php
function array_group(array $data, $by_column) {
    $result = [];
    foreach ($data as $item) {
        $column = $item[$by_column];
        unset($item[$by_column]);
        if (isset($result[$column])) {
            $result[$column][] = $item;
        } else {
            $result[$column] = array($item);
        }
    }
    return $result;
}
$activities = array(
    array('service_id' => '1',
          'servicename' => 'Incometax',
          'activity_id' => '1',
          'nameofactivity' => 'Return'),
    array('service_id' => '1',
          'servicename' => 'Incometax',
          'activity_id' => '2',
          'nameofactivity' => 'filling')
);
$activities = array_group($activities, 'servicename');
?>
<link href = "https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" rel = "stylesheet" />
<script src = "https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<?php foreach ($activities as $key => $act) { ?>
<div id="accordion">
    <h3>
        <label for='product-44-44'>
            <input type='checkbox'  name="arr[<?php echo $act[0]['service_id']; ?>][service]" value="<?php echo $act[0]['service_id']; ?>" id="<?php echo $act[0]['service_id']; ?>"/>
            <?php echo $key; ?>
        </label>
    </h3>
    <div class="columns">
        <?php foreach ($act as $value) { ?>
        <div class="d1">
            <label>
                <input type="checkbox" name="arr[<?php echo $value['service_id']; ?>][activity][]" value="<?php echo $value['activity_id']; ?>" id="<?php echo $value['activity_id']; ?>">
                <?php echo $value['nameofactivity']; ?>
            </label>
        </div>
        <?php } ?>
    </div>
</div>
<?php } ?>
<script>
    $("#accordion")
    .accordion({
        collapsible: true,
        active: false,
        heightStyle: "content",
        beforeActivate: function (event, ui) {
            var oldInput = ui.oldHeader.find('input');
            oldInput.prop('checked', !oldInput.prop('checked')) // this bit unchecks when the accordion is closed
            var newInput = ui.newHeader.find('input');
            // this bit checks when the accordion is opened
            newInput.prop('checked', !newInput.prop('checked'))
        }
    }
              );
</script>

相关问题