不能使用while循环而不是foreach循环for pagination php mysql

How can I replace the foreach loop that displays content fetched from a table, to being display using this while loop?

code of foreach loop is here : http://pastebin.com/pWpLwVH3

the while loop code is here: http://pastebin.com/XZH6GxmW

both are simple codes but cannot figure a way to use while instead of for. Am current doing pagination and pagination code unforutnately all come in while loop to display table fields.

have been trying for long but am always ending with some sort of error. last error was

invalid argument supplied foreach() when modified the code this way: http://pastebin.com/8bJDVhS8

thanks everyone! this forum has done wonders with me!

 $rows = $data_p = mysql_query("SELECT * FROM pharmacies $max") or die(mysql_error()); 
...
    <?php foreach($rows as $row): ?> 

You haven't FETCHED any rows, so you're trying to foreach on a statement result handle. The loop should be

<?php while($row = mysql_fetch_array($rows)) { ?>

instead.