Show days of single week I'm currently in the process of creating a online work schedule for internal use. For this, the client needs to show the days of a single week.

I pass a week number and a year.
From that I get the first day of that week, by using strtotime() passing an argument in the format [year]-W[weekno]-[dayofweek]. Example: strtotime('2011-48W-1');

With that function I create my table as mentioned earlier:

&lt;table class="weekly"&gt;

    &lt;thead&gt; 

        &lt;tr&gt;

            &lt;?php for($i = 1; $i &lt;= 7; $i++): ?&gt;

            &lt;th&gt;&lt;?php echo $dage[$i] . " ". date("j/m", strtotime($year.'-W'.$week.'-'.$i)); ?&gt;&lt;/th&gt;

            &lt;?php endfor; ?&gt;            

        &lt;/tr&gt;

    &lt;/thead&gt;

    &lt;tbody&gt;         

        &lt;tr&gt;

            &lt;?php for($i = 1; $i &lt;= 7; $i++): ?&gt;

            &lt;td&lt;?php if($i == 7) { echo ' class="last"'; } ?&gt;&gt;

                &lt;?php

                $day = date("Y-m-d", strtotime($year.'-W'.$week.'-'.$i));

                if(isset($entries[$day])):

                foreach($entries[$day] as $entry):

                ?&gt;      

                &lt;div class="workEntry" title="&lt;?php echo $entry-&gt;note; ?&gt;"&gt;

                    &lt;span&gt;

                        &lt;?php echo date("H:i", strtotime($entry-&gt;workStart)); ?&gt;

                        &lt;?php if($entry-&gt;workStart != "0000-00-00 00:00:00") { echo " - ".date("H:i", strtotime($entry-&gt;workEnd)); } ?&gt;

                    &lt;/span&gt;

                    &lt;span&gt;

                    &lt;?php if($entry-&gt;userId == 0): ?&gt;

                    Unspecifed

                    &lt;?php else: ?&gt;

                    &lt;?php echo $entry-&gt;name; ?&gt;, &lt;?php echo $entry-&gt;pgroup; ?&gt;

                    &lt;?php endif; ?&gt;

                    &lt;/span&gt;                     

                &lt;/div&gt;              

                &lt;?php endforeach;

                endif; ?&gt;

            &lt;/td&gt;

            &lt;?php endfor; ?&gt;            

        &lt;/tr&gt;   

    &lt;/tbody&gt;
&lt;/table&gt;


Well, it works, but I'm pretty sure that I'm reinventing the wheel, and doing a pretty bad job at it too. I'd like to know what you think and to hear any suggestions.
Three minor notes:


From Steve McConnell, Code Complete 2nd Edition, 31.2 Layout Techniques, p737:


  Using blank lines is a way to indicate how a program is organized. You can use them
  to divide groups of related statements into paragraphs, to separate routines from one
  another, and to highlight comments.


It does not make sense if all groups contain only one line.
strtotime($year.'-W'.$week.'-'.$i) is used and duplicated multiple times in the code. You could extract it out to a function to remove the duplication.
If I'm right you are iterating through the days of the week with this loop:


&lt;?php for($i = 1; $i &lt;= 7; $i++): ?&gt;



Renaming $i to $weekday or something similar would make it obvious and help readers/maintainers a lot.