display a simple calander in php
<p>I've got a table with dates &amp; days of the week, eg:
2012-05-01, Tuesday
2012-05-02, Wednesday etc.</p>

<p>I'm trying to display it in a calendar like table.  The problem is that for each day it is displaying it in a different row.</p>

<pre><code>$date4 = date("Y-m-d");
$date3 = date('Y-m-d',strtotime('-1 second',strtotime('+1 month',strtotime(date('m').'/01/'.date('Y').' 00:00:00'))));


    $sql3 = "SELECT * FROM trn_cal WHERE dat &gt;= '$date4' AND dat &lt;= '$date3'";
    $res3 = mysql_query($sql3);
    echo "&lt;table width='700px' border='1'&gt;";
    echo "  &lt;tr&gt;";
    echo "      &lt;td width='100px'&gt;Sunday&lt;/td&gt;";
    echo "      &lt;td width='100px'&gt;Monday&lt;/td&gt;";
    echo "      &lt;td width='100px'&gt;Tuesday&lt;/td&gt;";
    echo "      &lt;td width='100px'&gt;Wednesday&lt;/td&gt;";
    echo "      &lt;td width='100px'&gt;Thursday&lt;/td&gt;";
    echo "      &lt;td width='100px'&gt;Friday&lt;/td&gt;";
    echo "      &lt;td width='100px'&gt;Saturday&lt;/td&gt;";
    echo "  &lt;/tr&gt;";
    echo "&lt;/table&gt;";

    echo "&lt;table width='700px' border='1'&gt;";
    while ($row3 = mysql_fetch_assoc($res3)) {
    $weekday = $row3['weekday'];
    $weekdate = $row3['weekdate'];
    echo "  &lt;tr&gt;";
    echo "      &lt;td width='100px'&gt;";
    if ($weekday == "Sunday") {
    echo $weekdate;
    }
    echo "&lt;/td&gt;";
    echo "      &lt;td width='100px'&gt;";
    if ($weekday == "Monday") {
    echo $weekdate;
    }
    echo "&lt;/td&gt;";
    echo "      &lt;td width='100px'&gt;";
    if ($weekday == "Tuesday") {
    echo $weekdate;
    }
    echo "&lt;/td&gt;";
    echo "      &lt;td width='100px'&gt;";
    if ($weekday == "Wednesday") {
    echo $weekdate;
    }
    echo "&lt;/td&gt;";
    echo "      &lt;td width='100px'&gt;";
    if ($weekday == "Thursday") {
    echo $weekdate;
    }
    echo "&lt;/td&gt;";
    echo "      &lt;td width='100px'&gt;";
    if ($weekday == "Friday") {
    echo $weekdate;
    }
    echo "&lt;/td&gt;";
    echo "      &lt;td width='100px'&gt;";
    if ($weekday == "Saturday") {
    echo $weekdate;
    } 
    echo "&lt;/td&gt;";
    echo "  &lt;/tr&gt;";
    }
    echo "&lt;/table&gt;";
</code></pre>
