You#ve misunderstood me, I think. I know that the variable won't have a value outside of the loop. The final (failed) assignment which breaks you out of the loop will see to that. That's why you need to use the $lastrow.
while ($row = mysql_fetch_assoc($result))
{
echo '<tr><td>';
echo $row['course'];
echo '</td><td></td><td>';
echo $row['student'];
echo '</td><td></td><td>';
echo $row['ffnumber'];
echo '</td><td></td><td>';
echo $row['date'];
echo '</td><td></td><td>';
echo $row['completed'];
echo '</td></tr>';
$lastrow=$row
}
echo '</table><br />';
echo '<p><a href="excel2.php?id='.$lastrow['ffnumber'].'">View in Excel Format</a></p>'