The same code, only much tighter:
// generate a where clause to only look for your specific keys
// in the query...generates a clause like
// where key in ('2', '7', '9')
$query = "SELECT key, count(*) from $table WHERE key in ('" . implode("', '", $myarray) . "') GROUP BY key ORDER BY key";
// execute the query, only once needed
// ok so not ideal error checking
$result = mysql_db_query($db, $query);
// now just print everything out
while ( $row = mysql_fetch_row($result) ) {
print "<tr><td align=\"right\"><a href=\"cat.php3?l=$result[0]\">$myarray[$result[0]]</a></td> <td>: ";
print "$result[1]</td></tr>";
}
I find using my implode technique for IN's to be very easy to read and much less code (no stripping of last comma, etc.)