Create select for a table in PHP

0

I'm having trouble creating select for later use in a table.

The required SQL tables are as follows:

“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
    )

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

  • Column-Student#
  • Column-StudentName
  • Column-Numberofstudentsubjectsinarea1
  • Column-Numberofstudentsubjectsinarea2
  • Column-Ifyouadddisciplinesisgreaterthanorequalto6"Yes" (Admitted)
  • With the entities and relationships that exist between the tables, what do I have to do to SQL to populate the table?

    Currently I have the MVC skeleton and select of the rating table

    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;
    }
    
        
    asked by anonymous 10.12.2017 / 22:52

    1 answer

    2

    You can use query like 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

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

        
    11.12.2017 / 02:06