Php foreach loop displaying result only when the loop is completed?
-
Hi there, I have an array i need to loop though and echo each element. the way I want it to work is as follows: I would like the code to echo each element of the array as it gets to it. ( it will be more complicated than that since I will execute an operation on the array) I want to monitor the result for each element and the only way I can think of is to echo the result for each one. trouble is when i use foreach loop what happens is that all the results are printed at once when the script is done executing. thank you in advance for your help.
-
Answer:
Salaam for showing all ______________ $sql = "SELECT * FROM table1;"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)){ echo $row['name']; } for one by one ______________ $sql = "SELECT * FROM table1 where itemID=".$_GET['id']."; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)){ echo $row['name']; } Good Luck
Salmane S at Yahoo! Answers Visit the source
Other answers
You need to flush the output buffer, if you want the page sent to you sequentially, rather than after execution. You may also want to sleep() if you want it slow enough to see. i.e. ob_flush() http://php.net/manual/en/function.ob-flush.php
Rob
Related Q & A:
- How to solve the “Your search cannot be completed because of a service error” error in Search Center?Best solution by SharePoint
- How to write foreach with AND Condition?Best solution by Stack Overflow
- When i do a search and click on a result a get a page addressed rc10 overture what do i do?Best solution by Yahoo! Answers
- What is the difference between a for loop, a do while loop and a do loop?Best solution by wiki.answers.com
- Why is photoshop displaying images too bright?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.