Solved

Timing on a loop..

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

867 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

16 Experts available now in Live!

Get 1:1 Help Now