If you want to find last row in a table in your database there is no need to loop through to get the last record .Mysql provides you with a provision for that .
It is easy to find last row from table. The below query can be used to get last row from table.
$sql=”select * from <table name> order by <field name>desc limit 1″
It displays one last row from table.