title: Display image based on date in PHP
body: <p>Somewhere on my computer I had a PHP script for displaying an image based on the date, that would allow me to display different images on specific dates, or between selected dates, and display a default date if the current date wasn't one listed with a specific image to display.</p>
  
  <p>I recently had a problem with one of my hard drives though and lost a load of files, and I fear this script was one of the ones amongst them, as I can't find it anywhere. </p>
  
  <p>I can't remember where I found the script though. I've looked all over online and can't find it again. I thought it was here, but after searching around I can't find anything vaguely like it, let alone the script itself unfortunately. &lt;_&lt; </p>
  
  <p>Maybe I'm using the wrong search terms (I've been trying things like "php display image date"), but I'm finding nothing similar. </p>
  
  <p>Does anyone know of anything fitting the description above, or can suggest the best way to do this?</p>
  
  <p>I'm thinking that I need to specify a default image for if the current date's got a specific image specified and probably a case/break code block might be a better way to do it than if/else....</p>
  
  <p>Anyone got any thoughts on the best way to do this?</p>
  
  <p>Edit: Thanks everyone for your suggestions. I wasn't especially keen on using if/else/elseif, but in the end it seemed the easiest way to accomplish it. The way I've done it's probably not the most efficient way code-wise, but it works for now. </p>
  
  <p>(part of the code - it's rather long, so I won't bore you with it all)</p>
  
  <p>``Hmmm....okay, thanks. That explains why what I was trying to do wasn't working! :lol:</p>
  
  <p>Though I have seen other ways of doing it, including a foreach loop and GD, I stuck with the if/elseif/else in the end. It's probably not the most efficient way code-wise of doing it, but this worked in the end (part of the code anyway - it's a very long list, and I won't bore you with all of it!):</p>
  
  <pre><code>&lt;?php 
      // Macmillan Cancertalk week (21-25 Jan)
      if ((date('m') == 01) &amp;&amp; (date('d') &gt;= 21) || (date('m') == 01) &amp;&amp; (date('d') &lt;= 23)) {
      echo "&lt;img src=\"images/ribbons/cancertalk.gif\" height=\"145\" width=\"175\" alt=\"Macmillan Cancertalk\" /&gt;&lt;br /&gt;&lt;h6 class=\"awareness\"&gt;Macmillan Cancertalk Week &lt;span class=\"morelink\"&gt;&lt;a href=\"the-bookstall-cancer-links-and-resources.php\"&gt;more...&lt;/a&gt;&lt;/span&gt;&lt;/h6&gt;";
      }   
      // Macmillan Cancertalk week (21-25 Jan) and Cervical Cancer Awareness Week (24-30 Jan) 
      else if ((date('m') == 01) &amp;&amp; (date('d') == 24)) {
      echo "&lt;img src=\"images/ribbons/macmillan_cervical.gif\" height=\"145\" width=\"175\" alt=\"Macmillan Cancertalk and white and teal awareness ribbons\" /&gt;&lt;br /&gt;&lt;h6 class=\"awareness\"&gt;Macmillan Cancertalk Week &amp;amp; Cervical Cancer Awareness Week &lt;span class=\"morelink\"&gt;&lt;a href=\"the-bookstall-cancer-links-and-resources.php\"&gt;more...&lt;/a&gt;&lt;/span&gt;&lt;/h6&gt;";
      }   
      // Macmillan Cancertalk week (21-25 Jan), Cervical Cancer Awareness Week (24-30 Jan) and Beating Bowel Cancer - Be Loud Be Clear Week (25-31 Jan)   
      else if ((date('m') == 01) &amp;&amp; (date('d') == 25)) {
      echo "&lt;img src=\"images/ribbons/macmillan_cervical_bowel.gif\" height=\"145\" width=\"175\" alt=\"Macmillan Cancertalk, white &amp; teal awareness ribbons, and blue &amp; brown cancer awareness ribbons\" /&gt;&lt;br /&gt;&lt;h6 class=\"awareness\"&gt;Macmillan Cancertalk Week, Cervical Cancer Awareness Week, and Be Loud Be Clear Week (Beating Bowel Cancer) &lt;span class=\"morelink\"&gt;&lt;a href=\"the-bookstall-cancer-links-and-resources.php\"&gt;more...&lt;/a&gt;&lt;/span&gt;&lt;/h6&gt;";
      }
      // Beating Bowel Cancer - Be Loud Be Clear Week (25-31 Jan) 
      else if ((date('m') == 01) &amp;&amp; (date('d') == 31)) {
      echo "&lt;img src=\"images/ribbons/brown_blue_ribbon.gif\" height=\"145\" width=\"175\" alt=\"blue and brown cancer awareness ribbons\" /&gt;&lt;br /&gt;&lt;h6 class=\"awareness\"&gt;Be Loud Be Clear Week (Beating Bowel Cancer) &lt;span class=\"morelink\"&gt;&lt;a href=\"the-bookstall-cancer-links-and-resources.php\"&gt;more...&lt;/a&gt;&lt;/span&gt;&lt;/h6&gt;";
      }   
      // International Childhood Cancer Day (15 Feb)
      else if ((date('m') == 02) &amp;&amp; (date('d') == 15)) {
      echo "&lt;img src=\"images/ribbons/gold_ribbon.gif\" height=\"145\" width=\"175\" alt=\"gold cancer awareness ribbons\" /&gt;&lt;br /&gt;&lt;h6 class=\"awareness\"&gt;International Childhood Cancer Day &lt;span class=\"morelink\"&gt;&lt;a href=\"the-bookstall-cancer-links-and-resources.php\"&gt;more...&lt;/a&gt;&lt;/span&gt;&lt;/h6&gt;";
      }       
      // Gynaecological Cancers Campaign (1 Feb to 31 March)
      else if ((date('m') == 02) &amp;&amp; (date('d') &gt;= 01) || (date('m') == 02) &amp;&amp; (date('d') &lt;= 28)) {
      echo "&lt;img src=\"images/ribbons/teal_ribbon.gif\" height=\"145\" width=\"175\" alt=\"teal cancer awareness ribbons\" /&gt;&lt;br /&gt;&lt;h6 class=\"awareness\"&gt;Gynaecological Cancers Campaign (1st February &amp;ndash; 31st March) &lt;span class=\"morelink\"&gt;&lt;a href=\"the-bookstall-cancer-links-and-resources.php\"&gt;more...&lt;/a&gt;&lt;/span&gt;&lt;/h6&gt;";
      }   
      else {
      echo "&lt;a class=\"awareness_link\" href=\"the-bookstall-cancer-links-and-resources.php\"&gt;&lt;img src=\"images/ribbons/default_ribbon.gif\" height=\"145\" width=\"175\" alt=\"calendar\" /&gt;&lt;br /&gt;&lt;h6 class=\"awareness\"&gt;Check our awareness calendar for information about awareness events &amp;ndash; &lt;span class=\"morelink\"&gt;&lt;a href=\"the-bookstall-cancer-links-and-resources.php\"&gt;more...&lt;/a&gt;&lt;/span&gt;&lt;/h6&gt;&lt;/a&gt;";
      }
  ?&gt;
  </code></pre>