PHP & MySql WHILE loop 3 ; Not what you need? Reach out to all the awesome people in our web development community by starting your own topic. Loops are used to execute the same block of code again and again, as long as a certain condition is met. September 5, 2014, 2:01am #1. Hi guys, I have two tables. WHILE MyCondition DO--Commands. 1. Dave Scheuerman. The article contains information about the while loop in MySQL and its usage. I have a question regarding using a while loop to display the contents of a table. I am using a while loop to attempt to extract data from two columns in all of the rows of the table. Start New Topic. The while loop, which is one of the loops used in programming languages, is used for repetitive operations according to a condition. Functionally, the foreach and while implementations are equivalent. Im trying to build an online tool checkout application, so Im working with script 10.5 to pull (tool names) from a database to populate a table. Using while loop to display contents of a table. The idea of creating such a function is wrong. 2. Topics Feed. I am using php to display the data of the two columns id & product_name in each row. But the problem is that I'm running a mysql_query within a while loop, which I was told I should avoid. So if you don't want to use a while loop, but you still want to print the first and, for example, the fifth row, you can move the pointer using mysql_data_seek: mysql_data_seek() moves the internal row pointer of the MySQL result associated with the specified result identifier to point to the specified row number. 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. adamschroeder. Conceptually, a foreach is more appropriate, as a while loop has connotations of looping while a static condition holds, whereas foreach loops over elements of a collection. Different Types of Loops in PHP. 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. 3. While Loop in MySQL. Note: Field names returned by this function are case-sensitive. This means that the do...while loop will execute its statements at least … I am very new to mysql and php but trying to learn. You need some manual to see how to deal with loops in PHP. Note: This function sets NULL fields to the PHP null value. combining SQL and HTML in one function is a sign of VERY BAD design. The basic idea behind a loop is to automate the repetitive tasks within a program to save the time and effort. Note: In a do...while loop the condition is tested AFTER executing the statements within the loop. Read "Differences between a while loop and a for loop in PHP… PHP supports four different types of loops. Okay, here is complete code: