Create select for a PHP table

Asked

Viewed 372 times

0

I’m having trouble creating the select to later use in a table.

The mandatory SQL tables are the following:

“Aluno” (**PK:** id, numero, nome), 
“Area” (**PK:** id, nome), 
“UC” (**PK:** id, nome, **FK:** id_area) 
“Classificacao”
    (
      **PK:** id, 
      **FK:** id_uc, 
      **FK:** id_aluno,
      nota
    )

Goal is to create a table in php (mvc) as follows:

Tabela final

  1. Column - Student No
  2. Column - Student name
  3. Column - Nº disciplines of the student in the area 1
  4. Column - Nº disciplines of the student in the area 2
  5. Column - If the sum of disciplines is greater than or equal to 6 "Yes" (Admitted)

With the entities and relationships that exist between the tables, which select I have to do the SQL to fill the table?

I actually have the skeleton MVC and select of the leaderboard

function getClassificacao()
{
    $classificacao = array();

    $db=new db();
    $con=$db->connect();

    $sql_query = "SELECT * FROM classificacao";
    $result = $con->query($sql_query);

    $i = 0;
    while($row = mysqli_fetch_array($result))
    {
        $classificacao[$i]["id"] = $row["id"];
        $classificacao[$i]["id_uc"] = $row["id_uc"];
        $classificacao[$i]["id_aluno"] = $row["id_aluno"];
        $classificacao[$i]["nota"] = $row["nota"];
        $i++;
    }
    return $classificacao;
}

1 answer

2


You can use a querylike this:

SELECT aluno.nome AS 'Nome Aluno', aluno.numero AS 'Numero Aluno', area.nome AS 'Área', COUNT(area.id) AS 'Disciplinas da Área' FROM aluno INNER JOIN classificacao ON aluno.id = classificacao.id_aluno INNER JOIN uc on classificacao.id_uc = uc.id INNER JOIN area ON uc.id_area = area.id WHERE aluno.id = 1 GROUP BY area.id, aluno.nome;

This returns a result like

inserir a descrição da imagem aqui

I think this is what you want. Then it’s manipulating on the PHP / HTML side

  • I’m grateful, someone can separate by several selects?

  • Pq varios selects? You understand at least logic?

  • The problem is that, I did not understand the logic, I intend to divide by sub selects in order to understand and use later.

Browser other questions tagged

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