In my database classes, I've had 5 of em, one thing that they beat us over the head with was do not store that which you can calculate. It leads to problems.
Instead of storing the number of comments use the count command here is an example working on hypothetical tables.
Table Structure:
CREATE TABLE IF NOT EXISTS teachers (
ID BIGINT NOT NULL auto_increment,
fName VARCHAR(50) NOT NULL,
lName VARCHAR(50) NOT NULL,
School VARCHAR(100) NOT NULL,
PRIMARY KEY (ID),
INDEX fName (fName),
INDEX lName (lName),
INDEX School (School)
);
CREATE TABLE IF NOT EXISTS comments (
ID BIGINT NOT NULL auto_increment,
TeachID BIGINT NOT NULL,
Posted DATE NOT NULL,
Edited DATE NOT NULL,
Poster VARCHAR(50) NOT NULL,
Cmnt TEXT,
PRIMARY KEY (ID),
INDEX Edited (Edited),
INDEX Posted (Posted)
);
Assuming you want to list all of the teachers with the number of comments they have received you would do something like this.
$sql = "SELECT a.fName,a.lName,a.School,COUNT(b.ID) ";
$sql .= "FROM teachers as a, comments as b ";
$sql .= "WHERE a.ID = b.TeachID ";
$sql .= "GROUP BY b.TeachID ";
$sql .= "ORDER BY a.School";
This has the advantage of not needing to keep the number of comments field updated because it is updated when there is a change to the comments table.