$r=mysql_fetch-array($result)
gives you the next record in the resultset untill you run out of records.
But, you are not limited to fetching just the next record,
you can also define which of the records from the resultset you want to fetch next.
http://www.php.net/manual/en/function.mysql-data-seek.php
You can use mysql_data_seek() to move to record number X in your resultset.
So you can use mysql_num_rows() to get the number of records in your resultset, and use data _seek to move to each record when you want to fetch it.