3
I have two unrelated tables. One is of reports, where it contains names of teachers and their respective subject, the other table is called login, where it contains credentials of each teacher, their privilege and also their respective subject.
The idea of the login table is that, with the access of the teacher, he can visualize all the teachers of the report table when their subject is equal to that of the registered teacher, and that also the privilege of the teachers is of teacher.
LOGIN TABLE
id
nome
materia
privilegio
REPORT TABLE
nome
materia
QUERY USED:
SELECT diga_relatorio.nome, diga_relatorio.materia, diga_login.materia
FROM diga_relatorio, diga_login
WHERE diga_relatorio.materia='{$_SESSION['digaPrivilegio']}'
AND diga_login.privilegio='professor'
GROUP BY diga_relatorio.nome
ORDER BY diga_relatorio.nome
However, this way it is returned also the teachers with the position of coordinator, being wrong, since the hierarchy would be:
- COORDINATOR (view all others)
- SUPERVISOR (view only teachers of your subject)
- TEACHER (see for himself)
The group by is grouping teachers, since in the table reports the name each repeats at least 500 times.. Anyway I will test the query and soon give a feedback. Until then, thanks!
– Cobra
the query returns me the same results always, regardless of the value I pass to diga_login='...'. The idea is that the supervisor can only see those teachers who have the privilege of 'teacher'.
– Cobra
The query was: "SELECT diga_reportario.nome, diga_relatorio.materia, diga_login.materia FROM diga_relatorio INNER JOIN diga_login ON diga_relatorio.materia = diga_login.materia WHERE diga_relatorio.materia='{$_SESSION['digaMateria']}' AND diga_login.privilegio='professor' GROUP BY diga_relatorio.nome ORDER BY diga_relatorio.nome"
– Cobra
Someone give a return, please!
– Cobra
I do not understand the usefulness of the report column since its two columns are repeated in the first table. Anyway for what you want to try:
SELECT 
 diga_relatorio.nome,
 diga_relatorio.materia,
 diga_login.materia 
FROM 
 diga_relatorio 
INNER JOIN 
 diga_login 
ON 
 diga_relatorio.materia = diga_login.materia AND
 diga_relatorio.nome= diga_login.nome
WHERE 
 diga_relatorio.materia='{$_SESSION['digaPrivilegio']}' AND 
 diga_login.privilegio='professor' 
ORDER BY 
 diga_relatorio.nome
– matutano
Which column report? I’m sorry, but I don’t see the cited column.. Ah, the instruction you gave me did not return results. What I am thinking of doing is registering all teachers in the table of diga_login accompanied by their privilege, since all teachers of the report table will be present in login
– Cobra
I wanted to ask about the usefulness of the report table. Confirm this: Is the column name of the report table equal to the column name of the login table? Is the report table’s matter column equal to the login table’s matter? It’s just that I think you have the logs from the login table, duplicated in the matter table. Otherwise put a piece of the comic you have, because it is confused.
– matutano
Yes, that information is completely duplicated, and that is a problem that has existed for a long time. It turns out that these data are filled out per student, that is, a room with 40 students will create 40 records for a single teacher, since each teacher is evaluated by each student. All this was done in an excel, and now I’m exporting to MYSQL, and along with the import are coming several errors...
– Cobra