You could get the total number of rows of your result with:
////////
$nextQuery = "YOUR QUERY HERE";
$result = mysql_query($nextQuery);
$number = mysql_numrows($result);
///////
$number is how many rows you'll have and then when you are looping your results later (best to use a for loop for this one...) you can compare your counter to $number, ie.
/////////////
for($i=1;$i<=$number;$i++) {
//YOUR NORMAL CODE HERE
if($i == $number) {
//YOUR SPECIAL LAST TIME CODE HERE
}
}