1) don't use mysql_num_rows() to count rows. it runs like a dog on large tables.
2) avoid do/whiles() when you can because you're expecting the code to work and don't test it until after the first run through.
3) create an id auto_increment row on every table.
try the below to count table rows:
$count_results = mysql_db_query($db,"SELECT COUNT(id) as total FROM table");
$count_row = mysql_fetch_object($count_results);
$total = $count_row->total;
or:
$query = "SELECT *, COUNT(id) as total FROM table";
$query_results = mysql_db_query($db,$query);
while($row = mysql_fetch_object($query_results))
{
if($row->id == 1)
{
echo "First row";
}
else
{
echo "not the first row";
}
echo "Total Rows: ",$row->total;
}