Jump to content

Endless Loop?


947740

Recommended Posts

I am trying to display a list of timestamps from May 19th to August 1st of this year. I convert the starting and ending dates to timestamps and add the value to a variable, adding 86400 seconds, 1 day, to get the next day. For some reason the script times out. I tried changing August 1st to May 20th, but it still times out. Here are the two ways I have tried:

 

EDIT:

$start = strtotime("May 19,2008");

$end = strtotime("August 1, 2008");

 

<?
while ($start <= $end) {
$main_content .= "<br />$start";
$start + 86400;
}
?>

And

<?
for ($start; $start<= $end; $start + 84600) {
$main_content.= "<br />$start";
}

?>

 

Any help or insight would be appreciated.

Link to comment
https://forums.phpfreaks.com/topic/104300-endless-loop/
Share on other sites

If you still want to use a "for loop" change your code to:

<?php
$start = strtotime("May 19,2008");
$end = strtotime("August 1, 2008");
$info = $start;
for ($start = $info;$start<= $end; $start += 84600) {
$main_content.= "<br />$start";
}
?>

 

or

<?php
$start = strtotime("May 19,2008");
$end = strtotime("August 1, 2008");
tmp = array();
$info = $start;
for ($start = $info;$start<= $end; $start += 84600) {
$tmp[] = $start;
}
$main_content = implode('<br />',$tmp);
echo $main_content;
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/104300-endless-loop/#findComment-534072
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.