There are many ways of doing this, depending on what result you want.
One way would be from mysql. One would be a combination, and one would be pure PHP (and probably others).
If you want to ONLY display unique names, you can easily solve this in the query using the GROUP BY statement, i.e.
SELECT * FROM table GROUP BY hostname;
Will only display entries with unqiue 'hostname' contents. This is definitly the best if it does what you want.
However, if the point is to tell the user that there are duplicates, you have to do a bit more. Starting with a similar query;
SELECT * FROM table ORDER BY hostname;
Now we get a result set with all the hostnames, sorted by hostname. So we build a simple PHP script (using db_*, replace with whatever you use);
<?
$prevHost = "";
$dupeCount = 0;
$first = 1;
while ($oneRow = db_fetch_array($resultSet)) {
// Sloppy. Very sloppy.
if ($first) { $first = 0; $prevHost = $oneRow[hostname]; print "Host: $prevHost";}
if ($prevHost != $oneRow[hostname]) {
// new host, output dupe info from last
print " ($dupeCount duplicates)<br>";
print "Host: $oneRow[hostname]";
$prevHost = $onerow[hostname];
$dupeCount++;
} else {
$dupeCount++;
}
}
print " ($dupeCount duplicates)<br>";
?>
I won't bother telling you about the PHP-only solution (given an array). The code above is not very good, but in theory it does the job. You can rebuild it to use an array as source instead of a db_fetch_array() (use foreach()).
Hope it helped 🙂