`Ex_ID` int(11) NOT NULL auto_increment,
`N_Etudiant` varchar(25) NOT NULL,
`Professeur` varchar(50) NOT NULL,
`Foyer` varchar(50) NOT NULL,
`Motif` varchar(50) NOT NULL,
`Date` date NOT NULL,
`Notes` text NOT NULL,
`Autre` varchar(150) NOT NULL,
Do you know how GROUP BY works? It collapses rows into groups, so if you group by N_Etudiant it would give you all the rows for each student into one. you could then count that group.
That would give you how many times a student appeared in the table though and you want it how many times per teacher, so you'd group on N_Etudiant, Professeur.
that would give you how many times a student shows with each professor.
Does that make sense to you?
Now use a HAVING clause to count each group for what you are looking for.
First, get out of the habit entirely of using SELECT * except in very specific cases.
Your results aren't good because you collapsed your rows by professor only and not by each student as well.
First just figure out the student, professor, you are close:
Code:
SELECT
N_Etudient,
Professeur
FROM
Expulsion
GROUP BY
N_Etudient,
Professeur
HAVING
COUNT(*) >= 2
without the group by student you were only counting how many times a professor showed up so if he showed up twice for Gary and once for Tim he would show up a total of three times. and you only want it for Gary.
Last edited by guelphdad; 11-25-2011 at 01:24 PM..
ok so i got this going.email part works but i can't seem to echo the teacher and student name?
PHP Code:
$query = "SELECT N_Etudiant, Professeur FROM Expulsion GROUP BY N_Etudiant, Professeur HAVING COUNT( * ) >=2 LIMIT 0 , 30"; $result = mysql_query ($query) or die ('Your query did not match any results: ' . mysql_error());
if (mysql_num_rows($result)>0)
{
while($row=mysql_fetch_array($result))
{
// multiple recipients $to = 'techker@gmail.com'; // note the comma
// To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Mail it mail($to, $subject, $message, $headers);
Alright so it sums up to this..really appreciat the help guys!super forum!!
PHP Code:
$query = "SELECT N_Etudiant, Professeur FROM Expulsion GROUP BY N_Etudiant, Professeur HAVING COUNT( * ) >=2 LIMIT 0 , 30"; $result = mysql_query ($query) or die ('Your query did not match any results: ' . mysql_error()); $row = mysql_fetch_assoc($result);
// multiple recipients $to = 'techker@gmail.com'; // note the comma
// subject $subject = 'Suivis Requis';
// message $message = "Suivis avec $prof pour Etudiant $eleve...";
// To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Mail it mail($to, $subject, $message, $headers);