947740 Posted May 6, 2008 Share Posted May 6, 2008 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 More sharing options...
DarkWater Posted May 6, 2008 Share Posted May 6, 2008 <? for ($start; $start<= $end; $start + 84600) { $main_content.= "<br />$start"; } Set $start equal to something, or leave it out. I think. Try: <? for (;$start<= $end; $start + 84600) { $main_content.= "<br />$start"; } Link to comment https://forums.phpfreaks.com/topic/104300-endless-loop/#findComment-534037 Share on other sites More sharing options...
947740 Posted May 6, 2008 Author Share Posted May 6, 2008 Still not working. <? $start = strtotime("May 19,2008"); $end = strtotime("August 1, 2008"); $info = $start; for ($start = $info;$start<= $end; $start + 84600) { $main_content.= "<br />$start"; } ?> Link to comment https://forums.phpfreaks.com/topic/104300-endless-loop/#findComment-534041 Share on other sites More sharing options...
DarkWater Posted May 6, 2008 Share Posted May 6, 2008 Echo out $start and $end and tell me what's in them. I think you used strtotime() incorrectly. Link to comment https://forums.phpfreaks.com/topic/104300-endless-loop/#findComment-534044 Share on other sites More sharing options...
947740 Posted May 6, 2008 Author Share Posted May 6, 2008 Start: 1211173200 | End: 1211259600 Link to comment https://forums.phpfreaks.com/topic/104300-endless-loop/#findComment-534047 Share on other sites More sharing options...
DarkWater Posted May 6, 2008 Share Posted May 6, 2008 I changed your while loop because you didn't add to $start correctly and it worked for me: $start = strtotime("May 19,2008"); $end = strtotime("August 1, 2008"); while ($start <= $end) { $main_content .= "<br />$start"; $start += 86400; } Link to comment https://forums.phpfreaks.com/topic/104300-endless-loop/#findComment-534056 Share on other sites More sharing options...
947740 Posted May 6, 2008 Author Share Posted May 6, 2008 Wow. It is amazing how something like that can throw your code off. Thanks a lot. (By the way, it worked. ) Link to comment https://forums.phpfreaks.com/topic/104300-endless-loop/#findComment-534059 Share on other sites More sharing options...
DarkWater Posted May 6, 2008 Share Posted May 6, 2008 Lol, no problem. =) Link to comment https://forums.phpfreaks.com/topic/104300-endless-loop/#findComment-534061 Share on other sites More sharing options...
kenrbnsn Posted May 6, 2008 Share Posted May 6, 2008 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 More sharing options...
947740 Posted May 6, 2008 Author Share Posted May 6, 2008 Thanks. It still goes back to that darn +=. Link to comment https://forums.phpfreaks.com/topic/104300-endless-loop/#findComment-534304 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.