Group data into a php table according to the discipline

Asked

Viewed 39 times

-1

My need is to group the concepts according to the discipline, follows the model:

inserir a descrição da imagem aqui

How to do: (I’m not able to group in a "title", only.

inserir a descrição da imagem aqui

Follow a code of the party in question. (If necessary, I make available).

    <?php
  $curType = '';

  if(strpos($class->name, '1º Ano') !== false)
    $curType = '1º Ano';
  if(strpos($class->name, '2º Ano') !== false)
    $curType = '2º Ano';

  $conceitos = [];

  foreach($subjects as $subject) {
    array_push($conceitos, $this->db->get_where('learning_goals', array(
      'type' => $curType,
      'eixos' => $i.'º Bimestre',
      'subject_id' => $subject['subject_id'],
    ))->result_array());
  }

  $eixos = [];
  $_subjects = [];

  foreach($conceitos as $conceito) {

   if(in_array($conceito['eixos'], $eixos))
     continue;
   array_push($eixos, $conceito['eixos']);

        $_descs = [];
        $descs = [];

        foreach($subjects as $subject) {
          array_push($_descs, $this->db->get_where('learning_goals', array(
            'type' => $curType,                
            'eixos' => $i.'º Bimestre',
            'subject_id' => $subject['subject_id'],
          ))->result_array());
        }

        foreach($_descs as $_desc) {
          foreach($_desc as $_des) {
            array_push($descs, $_des);
          }
        }

        foreach($descs as $key => $desc) {
          $descStatus = $this->db->get_where('learning_goals_status', array(
            'exam_id'     => $i,
            'conceito_id' => $conceito[0]['id'],
            'student_id'  => $stu->student_id,
          ))->row();

          $subject = $this->db->get_where('subject', array('subject_id' => $desc['subject_id'],
          ))->row();

          $key++;
      ?>
        <div class="col-xs-11 text-center">HABILIDADES QUE A CRIANÇA DEMONSTRA EM <?= $subject->name?></div>
        <div class="col-xs-11 <?php if($key == sizeof($descs)) { echo 'border-bottom'; } ?> border-top border-bottom border-left border-right"><?= $desc['sys_id'] ?>. <?= $desc['description'] ?></div>
        <div class="col-xs-1 <?php if($key == sizeof($descs)) { echo 'border-bottom'; } ?> border-bottom border-top border-right"> <?= $descStatus->status ?></div>
    <?php
      }
    ?>
<?php
  }
?>

  • You could send full code. That would help a lot.

  • Sure. I’ll edit and make available.

1 answer

1


I believe your title is repeating itself because it is being printed inside the loop foreach(), I believe it’s just to print it before the loop:

REPLY

<?php
$curType = '';

if(strpos($class->name, '1º Ano') !== false)
    $curType = '1º Ano';
if(strpos($class->name, '2º Ano') !== false)
    $curType = '2º Ano';

$conceitos = [];

foreach($subjects as $subject) {
    array_push($conceitos, $this->db->get_where('learning_goals', array(
        'type' => $curType,
        'eixos' => $i.'º Bimestre',
        'subject_id' => $subject['subject_id'],
    ))->result_array());
}

$eixos = [];
$_subjects = [];

foreach($conceitos as $conceito) {

    if(in_array($conceito['eixos'], $eixos))
        continue;
    array_push($eixos, $conceito['eixos']);

    $_descs = [];
    $descs = [];

    foreach($subjects as $subject) {
        array_push($_descs, $this->db->get_where('learning_goals', array(
            'type' => $curType,                
            'eixos' => $i.'º Bimestre',
            'subject_id' => $subject['subject_id'],
        ))->result_array());
    }

    foreach($_descs as $_desc) {
        foreach($_desc as $_des) {
            array_push($descs, $_des);
        }
    }

    echo "<div class="col-xs-11 text-center">HABILIDADES QUE A CRIANÇA DEMONSTRA EM <?= $subject->name?></div>";
    foreach($descs as $key => $desc) {
        $descStatus = $this->db->get_where('learning_goals_status', array(
            'exam_id'     => $i,
            'conceito_id' => $conceito[0]['id'],
            'student_id'  => $stu->student_id,
        ))->row();

        $subject = $this->db->get_where('subject', array('subject_id' => $desc['subject_id'],
    ))->row();

        $key++;
        ?>
        <div class="col-xs-11 <?php if($key == sizeof($descs)) { echo 'border-bottom'; } ?> border-top border-bottom border-left border-right"><?= $desc['sys_id'] ?>. <?= $desc['description'] ?></div>
        <div class="col-xs-1 <?php if($key == sizeof($descs)) { echo 'border-bottom'; } ?> border-bottom border-top border-right"> <?= $descStatus->status ?></div>
        <?php
    }
    ?>
    <?php
}
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.