1
In my comic book, I have 4 tables: Aluno
, Ano
, Matérias
and Nota
. They are mounted as follows:
Tabela :: Colunas
----------------------------------------------------------
Aluno :: AlunoID | AlunoNome | AnoID
Ano :: AnoID | AnoNome
Materia :: MateriaID | MateriaNome | AnoID
Nota :: NotaID | AlunoID | MateriaID | Nota
I’m trying to use a inner join
to unite all data:
Aluno a INNER JOIN Ano b on ( a.AnoID = b.AnoID )
INNER JOIN Materia c on ( b.AnoID = c.AnoID )
INNER JOIN Nota d on ( a.AlunoID = d.AlunoID )
In fact, I’m able to put the data together! Only I’m having a problem -
on the table Aluno
, I have two records. When I use the echo
to display the students, the names repeat to each subject and each note.
It looks something like this:
Aluno1 Ano1 Materia1 Nota1
Aluno1 Ano1 Materia2 Nota1
Aluno1 Ano1 Materia1 Nota2
Aluno1 Ano1 Materia2 Nota2
Aluno2 Ano2 Materia3 Nota3
Aluno2 Ano2 Materia4 Nota4
Aluno2 Ano2 Materia3 Nota3
Aluno2 Ano2 Materia4 Nota4
As can be seen in the example above, the query result repeats the name and matter, and toggles the display of the rest of the results!
I would like the result to be something like this:
Aluno1 Ano1 Materia1 => Nota1 / Materia2 => Nota2
Aluno2 Ano2 Materia3 => Nota3 / Materia4 => Nota4
As you can see, the name now repeats only once and the other information relating to that name is placed beside it!
I know I can solve this "problem" by increasing the number of columns in the table aluno
, placing multiple columns calls notai
, guy nota1
, nota2
, nota3
, but that way I’ll be very limited.
My doubt then is:
How to join the tables in such a way that the names do not keep repeating and the information related to the student appear beside?
I would like to establish the real relationship, since a student belongs to a specific year, that specific year has X amount of subjects and each student of each year earned Y grade in X subject.
I’m not able to do it, it’s getting all dolled up like in the above examples.
this is one way, I’m locating another: http://answall.com/questions/38809/70
– Bacco
one more: http://answall.com/questions/105060/70
– Bacco
Basically you create a variable
$nomeAnterior = ''
, and makes aif( $campo['nome'] != $nomeAnterior) { mostra o nome, e guarda ele em $nomeanterior
, otherwise shows only note and matter.– Bacco
I think your last Join needs one more relationship between matter and note
– Marco Souza
@Bacco can you help me with some doubts? Could we start a discussion based on this question?
– ivan veloso
@Did you see my answer? She helped you?
– Victor Stafusa
@Victorstafusa in yes and no other terms! I think the crucial part to my problem is to design my idea better! if you have how we talk better about it! It would be very useful!
– ivan veloso