No, theoretically it doesn't work. Look at your loop: you loop through the number of categories. So for the first category (category 0) yes, it'd be fine. But after that (when $i>=1) it is not guaranteed that there is more than one image.
Think, using this:
$image = mysql_result($getImage, $i, "filename");
if $i = 5, and there are only 4 images in that category, then you'll get a jump error. If the category is empty of images, you get an error. So in theory, your code doesn't work.
Look, I can't really "fix" your code, mainly because I don't understand what you're trying to do.
Perhaps something like this would be better for you:
$getCategories = mysql_query("select name, cid, novisitors from $categoryTable");
$noCategories = mysql_num_rows($getCategories);
echo "<table class=\"table\">\n
<tr>\n";
for ($i = 0; $i < $noCategories; $i++) {
$name = mysql_result($getCategories, $i, "name");
$cid = mysql_result($getCategories, $i, "cid");
$getImage = mysql_query("SELECT pid, cid, filename FROM $photoTable WHERE cid='$cid'");
$totalpics = mysql_num_rows($getImage);
$c = 1;
for($k=0; $K<$totalpics; $k++)
{
$image = mysql_result($getImage, $i, "filename");
$novisitors = mysql_result($getCategories, $i, "novisitors");
echo "\t<td><a href=\"album.php?cid=$cid\"><img alt=$pid class=\"border\" src=\"$photoDir/tb_$image\"></a>";
echo "<br><div align=\"center\">$totalpics Pics</div></td>\n";
if($c%5==0)
{
// Modolus operator:
// If there is no remainder when divided by 5
// i.e. 5,10,15,20,25
echo '</tr><tr>';
}
}
}
echo "</tr>\n
</table>\n";