How to know the index number in a multidimensional array?

Asked

Viewed 124 times

1

Information:
Rooms: 25;
Teachers: 4;
Q02, Q03, Q04: A student in a class classified the teacher from 0 to 10. From these numbers, a media was generated.

There is a select with the list of teachers, and when one is selected, I need to display ALL the classrooms that the same of the class (done), his position (among the four teachers) based on the average (IN THAT SAME ROOM), that for Q02, Q03 and Q04. There is also a GENERAL media concept, which will be done not only with the teachers who teach in that class, but all the teachers of all the classrooms.

EXPLANATION OF THE ARRAY

explicacao

EXPECTED RESULT

array de dados

SAMPLE OF THE DATABASE DATA

inserir a descrição da imagem aqui

SCRIPT:

<?php
require 'config.php';
$nomeProfessor = (isset($_POST['frmProfessor'])) ? addslashes($_POST['frmProfessor']) : 'ABNER';

//LISTA TODOS OS PROFESSORES
$listaProfessor = new Read;
$listaProfessor->FullRead("SELECT Nome FROM ang_relatorio GROUP BY Nome");

//LISTA TODAS AS SALAS DO PROFESSOR
$listaSalaProfessor = new Read;
$listaSalaProfessor->FullRead("SELECT Sala, Nome FROM ang_relatorio WHERE Nome=:professor GROUP BY Sala", "professor={$nomeProfessor}");

//LISTA TODAS AS SALAS
$todasSalas = new Read;
$todasSalas->FullRead("SELECT Sala FROM ang_relatorio GROUP BY Sala");

$media = new Read;
//SELECIONA A MEDIA DO PROFESSOR EM UMA SALA E ARMAZENA EM UM ARRAY
foreach ($listaSalaProfessor->getResult() as $key => $sala):
    extract($sala);
    $media->FullRead('SELECT (AVG(Q02) + AVG(Q03) + AVG(Q04)) / 3 FROM ang_relatorio WHERE Nome=:professor AND Sala=:sala', "professor={$nomeProfessor}&sala={$Sala}");
    $mediaProfessorSala[] = $media->getResult();
endforeach;

foreach ($todasSalas->getResult() as $key => $sala):
    extract($sala);
    $selecionaSala = new Read;
    $selecionaSala->FullRead("SELECT Nome, Sala, (AVG(Q02) + AVG(Q03) + AVG(Q04)) / 3 FROM ang_relatorio WHERE Sala=:sala GROUP BY Nome ORDER BY (AVG(Q02) + AVG(Q03) + AVG(Q04)) / 3 DESC", "sala={$Sala}");
    $professoresSala[] = $selecionaSala->getResult();
endforeach;

//RETORNA O CONCEITO DO PROFESSOR REFERENTE AOS OUTROS
function Conceito($posicao) {
    if ($posicao <= 7):
        return 'C';
    elseif ($posicao >= 8 && $posicao <= 14):
        return 'B';
    elseif ($posicao >= 15 && $posicao <= 21):
        return 'A';
    else:
        return 'Posição incorreta.';
    endif;
}
?>

<!DOCTYPE html>
<html lang="pt-br">
    <head>
        <meta charset="utf-8">
        <title>Relatórios</title>
        <link rel="stylesheet" href="<?= URL; ?>/assets/css/bootstrap.css"/>
        <link rel="stylesheet" href="<?= URL; ?>/assets/css/awesome.css"/>
        <link rel="stylesheet" href="<?= URL; ?>/assets/css/estilo.css"/>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <div class="container">

            <form method="POST">
                <select name="frmProfessor" class="form-control" onchange="this.form.submit()">
                    <?php
                    foreach ($listaProfessor->getResult() as $key => $professor):
                        extract($professor);
                        $selected = ($Nome == $nomeProfessor) ? 'selected' : '';
                        echo "<option value='{$Nome}' $selected>{$Nome}</option>";
                    endforeach;
                    ?>
                </select>
            </form>

            <table class="table table-bordered">
                <tr>
                    <th>#SALA</th>
                    <th>#Q02</th>
                    <th>#Q03</th>
                    <th>#Q04</th>
                </tr>
                <tr>
                    <td>SALA</td>
                    <td>POSIÇÃO DO PROFESSOR REFERENTE AOS OUTROS COM BASE NA MEDIA DE Q02</td>
                    <td>POSIÇÃO DO PROFESSOR REFERENTE AOS OUTROS COM BASE NA MEDIA DE Q03</td>
                    <td>POSIÇÃO DO PROFESSOR REFERENTE AOS OUTROS COM BASE NA MEDIA DE Q04</td>
                </tr>
            </table>
        </div>
    </body>
</html>
No answers

Browser other questions tagged

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