Solved

Timing on a loop..

Posted on 2008-10-01
3
206 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now