Select count() question for an image gallery

I’ve pieced together some code to make a image gallery for our site. Problem is I have thumbnails repeated in a table on the left and then a “view” link on the right (links to a larger image) repeated in another table. Really I want to combine these into one linked thumbnail in one table. But the left thumbnails come from a SELECT statement whereas the “view” link comes from a SELECT COUNT() and for the life of me I can’t see how to combine these into one statement (I am a total beginner in php).

Testing site page is here: http://www.artplacement.org/gallery/artists_results_byartist_test.php?lastname=Christie

php code to generate thumbnails is:



<?php
$lastname = $_GET['lastname'];
$par=("SELECT lastname, inventory FROM gallery_inventory WHERE lastname = '$lastname' ORDER BY inventory desc");
$result = @mysql_query($par);
while ( $row = mysql_fetch_array($result) ) {
    
echo '<tr>';
echo '<td height="325" valign="middle">';
echo '<img src="images/artist_images/' . $row['lastname'] . '/' . 'images/icons/' . $row['inventory'] . '.jpg"' .  '">';
echo '</td>';
echo '</tr>';
    
}
?>


php code to generate “view” link is:



<?php 
$sql = "SELECT COUNT(inventory) FROM gallery_inventory WHERE lastname = '$lastname'"; 
$rs_result = mysql_query($sql,$db); 
$row = mysql_fetch_row($rs_result); 
$total_records = $row[0]; 
$total_pages = ceil($total_records / 1); 
for ($i=1; $i<=$total_pages; $i++) { 

echo '<tr>';
echo '<td height="325" valign="middle">';
echo '<a href="artists_results_byartist_test_large.php?lastname=' . $lastname . '&page=' . $i . '">view</a>'; 
echo '</td>';
echo '</tr>';
    
}; 
?>      


Any help is appreciated.
Thanks
Jonathan

Simply put, you dont want to combine them.

Is there any other way I can approach this?

Get rid of the second query [FPHP]mysql_num_rows[/FPHP] the first

Thank-you very much. Got it working.