psquillace Posted March 16, 2008 Share Posted March 16, 2008 Hello All: I want to write a script where a few .jpgs that I have would change on a specific date (seasonally). Being new to php I was wondering if I should do something like IF date() 'img src"" ' ; }else{ echo img... bla bla bla but I am not sure of the exacts of how I can do this, Any help or advice is much appreciated, Paul Quote Link to comment Share on other sites More sharing options...
JD* Posted March 16, 2008 Share Posted March 16, 2008 what are your seasons that you want to change it on? You can use the date command to find out the current date,time, month, etc and then compare it to your pre-made selection, ie: <?php if(date("m") >=11 && date("m") <=04) { //winter } elseif(date("m") >=05 && date("m") <=06) { //spring } elseif(date("m") >=07 && date("m") <=10) { //summer } else { //fall } ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 16, 2008 Share Posted March 16, 2008 <?php $date=date("m"); if($date==12){ $img="<img src='xmas.jpg' />"; }elseif($date==02){ $img="<img src='winter.jpg' />"; }else{ $img="<img src='nopic.jpg' />"; } echo $img; ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 16, 2008 Share Posted March 16, 2008 Better all year example.......... <?php $x=array("01"=>"january.jpg","02"=>"febuary.jpg","03"=>"march.jpg", "04"=>"april.jpg","05"=>"may.jpg","06"=>"june.jpg","07"=>"july.jpg", "08"=>"august.jpg","09"=>"september.jpg","10"=>"october.jpg", "11"=>"november.jpg", "12"=>"december.jpg"); $date=date("m"); foreach($x as $key=> $val){ if($date==$key){ echo"<img src='$val'/>"; } } ?> Quote Link to comment Share on other sites More sharing options...
psquillace Posted March 16, 2008 Author Share Posted March 16, 2008 wow! Thanks guys.... I did not know there were so many ways to do this. Ok, I will try them out.... Thanks for the help. Paul Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.