Create an associative array using the task # as the key, then if the row already exists modify it. Once you've finished going through your data set you just use the array to print.
Without knowing exactly what data you are looking for here is some code that might work.
$query = "SELECT task_num FROM table";
$result = mysql_query($query);
$tasks = array();
while ($row = mysql_fetch_row($result) {
if ($tasks[$row["task_num"]]) {
$tasks[$row["task_num"]]++;
}
else {
$tasks[$row["task_num"]] = 1;
}
for (reset($tasks); $key = key($tasks); next($tasks)) {
print "$key = " . $tasks[$key];
}
You should be able to figure it out from that.