Jump to content

Any better way to do this?


longhollow

Recommended Posts

I'm not a PHP guy, just cut and paste code sometimes.  This works but it isn't very elegant.  My page gets lots of views and I would like to reduce machine overhead and deliver the page as fast as possible.  Any suggestions?  Thanks!

 

I'm creating a list of links on a page.  Each day the link thats 7 days old drops off and a new one appears.  The .txt files have the html link code for one day.

 

<?$today = date("z",(time()-3600))+1;?>

<?$today1 = date("z",(time()-3600));?>

<?$today2 = date("z",(time()-3600))-1;?>

<?$today3 = date("z",(time()-3600))-2;?>

<?$today4 = date("z",(time()-3600))-3;?>

<?$today5 = date("z",(time()-3600))-4;?>

<?$today6 = date("z",(time()-3600))-5;?>

 

<ul>

<li><?INCLUDE "/usr/home/bcmurray/public_html/features/$today.txt";?></li>

<li><?INCLUDE "/usr/home/bcmurray/public_html/features/$today1.txt";?></li>

<li><?INCLUDE "/usr/home/bcmurray/public_html/features/$today2.txt";?></li>

<li><?INCLUDE "/usr/home/bcmurray/public_html/features/$today3.txt";?></li>

<li><?INCLUDE "/usr/home/bcmurray/public_html/features/$today4.txt";?></li>

<li><?INCLUDE "/usr/home/bcmurray/public_html/features/$today5.txt";?></li>

<li><?INCLUDE "/usr/home/bcmurray/public_html/features/$today6.txt";?></li>

</ul></li>

 

Link to comment
https://forums.phpfreaks.com/topic/149003-any-better-way-to-do-this/
Share on other sites

not sure if u can make it faster, but u can definitely reduce the lines of code..

 

<ul>
<?php 
for($i=1; $i>=-5; $i--) {
$today = date("z",(time()-3600))+$i;
?>
 <li><? INCLUDE "/usr/home/bcmurray/public_html/features/$today.txt";?></li>
<?php 
}
?>
</ul>

 

PS: the code is not tested..

 

beaten by Mchl ;)

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.