Solved

Timing on a loop..

Posted on 2008-10-01
3
209 Views
Last Modified: 2008-10-02
$result = mysql_query($query);
echo mysql_error();
 while($row = mysql_fetch_array($result)){
        $search = $row[0];
        echo $search;

I have this.  The final result will be different but I will be able to illustrate my question.   I want to loop the results one by one, one every 15 second and then the next row.  What would be the best way to do this?  For the end result I'll strictly be doing stuff that doesn't display on the screen but I'm not sure what the consequences are of running a loop with potentially thousands of records in a database.

.. Is it even possible to add timing to a php while loop..
0
Comment
Question by:cstormer
  • 2
3 Comments
 
LVL 27

Expert Comment

by:yodercm
ID: 22621012
$result = mysql_query($query);
echo mysql_error();
 while($row = mysql_fetch_array($result)){
        $search = $row[0];
        echo $search;
        sleep(15);
}
0
 

Author Comment

by:cstormer
ID: 22621161
This does work, when it's finish with the whole query it displays.

What are the concequences of running this against a few thousand records?
0
 
LVL 27

Accepted Solution

by:
yodercm earned 500 total points
ID: 22623120
It will take a few thousand x 15 seconds to run the script.  The query is done only only once, so the time is not of consequence to the database.  However, you may need to set your php time limit to ensure the program continues running.

set_time_limit(150000);

You may also need to check with your webhost or the server settings to ensure that this will work.  I'm not personally familiar with how the time limits are enforced.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question