 <p>Then it is as simple as:</p> <pre><code>$data=getAllData(); $counted = count($data); $i = 1; foreach($data as $row) { . .Processing $i of $counted records . $i++; } </code></pre> <p>And! I strongly recommend you to use PDO. Find documentation <a href="http://php.net/manual/ro/book.pdo.php" rel="nofollow">HERE</a></p> <p>Hope this helps! :D</p>