My database is called: students
MY students table is: students with columns:
STUDENT_ID , STUDENT NAME, ETC.
My absences table is: absences with columns:
ABSENCE_ID, STUDENT_ID, ETC.
it should count how many absence records per student i have taking in consideration the students_id and to show the students_id
in the table for example:
+------------+-----------+
| STUDENT ID | ABSENCES |
+------------+-----------+
| 1 | 3 |
| 2 | 8 |
| 3 | 437 |
+------------+-----------+
NOTE: THE STUDENT_ID MUST BE READ FROM STUDENTS TABLE NOT FROM ABSENCES TABLE THIS IS THE PROBLEM!!!!
THESE ARE MY TWO QUERIES
$result = mysql_query("SELECT student_id, COUNT(*) AS count FROM absences GROUP BY student_id ORDER BY count DESC;");
$result2 = mysql_query("SELECT students.student_id, absences.student_id FROM students INNER JOIN absences ON students.student_id = absences.student_id");
The first query is working fine (It counts the records on table and tells me how many absences are)
The second query is not working, i want this query to work and to make ONE QUERY for both
My php code looks like this:
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td><font size=\"4\" color=\"white\">" . $row['student_id'] . "</font></td>";
echo "<td><font size=\"4\" color=\"white\">" . $row['count'] . "</font></td>";
echo "</tr>";
}