Functionally, the foreach and while implementations are equivalent. An important thing to note is that using mysql_fetch_assoc() is not significantly slower than using mysql_fetch_row(), while it provides a significant added value. But the problem is that I'm running a mysql_query within a while loop, which I was told I should avoid. It is my understanding that a mysql_fetch_array will only return 1 row unless it is used in conjunction with a while loop, which then should return all rows. 1. I need to be able to select multiple tools (using checkboxes), and then submit that form to a shopping cart. The while loop, which is one of the loops used in programming languages, is used for repetitive operations according to a condition. I am using php to display the data of the two columns id & product_name in each row. WHILE MyCondition DO--Commands. Topics Feed. Using while loop to display contents of a table. adamschroeder. combining SQL and HTML in one function is a sign of VERY BAD design. Start New Topic. Okay, here is complete code: