This is the script I use. There's a chunk of the page to give you the idea. I was beating myself up and had to ask for help also.
$result= mysql_query("SELECT DISTINCT
products.company,
products.id,
pix.image,
category.cat_number,
COUNT(products.id) AS NUM
FROM category, pix, products
WHERE category.cat_number = '$array'
AND category.id = products.id
AND category.id = pix.id
GROUP BY products.id
ORDER BY products.id ASC
LIMIT ".$from.",".$result1) or die ('result error');
$count = mysql_num_rows($result);
$rows = mysql_fetch_array($result)or die (' array error');
?>
<table border="0" cellpadding="10">
<tr>
<?php
$i = 1;
while($rows = mysql_fetch_array($result)){
?>
<td><a href='<?php echo $rows['company']."_".$rows['id'].".html"; ?>'><img src="<?php echo $rows['image']; ?>"width="150"></td>
<?php
if ($i%3) {
} else {
if ($i >= $count) {
} else {
echo "</tr><tr>";
}
}
$i++;
}
?>
</tr>
</table>
<?php
include 'pagebottom.html';
?>