There are much better ways doing this like using a proper sql statement, but in the mean time perhaps u can do this.
//get all the names
$query = mysql_query ("select names from people");
//Loop through the names
foreach (mysql_fetch_array($query) as $temp) {
$query2 = mysql_query("select * from comments where name='" . $temp['name'] . "'");
//count the comments
$no_comments = mysql_num_rows($query2);
//print
echo $temp['name'] . ": $no_comments";
}
// Will print
// Mr Lim = 100
// Mrs Wan = 29
// so on.
// Please remember this snip does not include error check, its recommended that u include checks like Unable to connect to database, no results or something within the loop.
There r much better solutions out there, but still, hope this helps.