Here is an example of a function that was created to count the number of book spreads attached to a certain book number. The problem was there were more than one book number attached to a whole table of bookspreads. By using SQL COUNT and WHERE it is possible to find the total count of entries with the same field input.
$book // the book number i wanted to count if a spread was attached to it
function spreadcount($book){
$query = "SELECT COUNT(*) FROM table WHERE book={$book} ";
$result = mysql_query($query) or die(mysql_error());
echo mysql_result($result,0); // 0 pulls the first result which is our magic number.
}