Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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!

share|improve this question

1 Answer

up vote 1 down vote accepted
 $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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.