Building a weekly celendar PHP & Tables

Hello,

I hope this question goes into the right forum part.
I an unable to figure out how to get a weekly view in calendar to render properly.

I have done two different codes that results in the same render.
Here goes the code.


// $result comming from SQL Query.
array (size=9)
  0 =>
    array (size=3)
      'BookedDate' => string '2013-08-15' (length=10)
      'BookedTime' => string '800' (length=3)
      'ScheduleInterval' => string '40' (length=2)
  1 =>
    array (size=3)
      'BookedDate' => string '2013-08-13' (length=10)
      'BookedTime' => string '1000' (length=4)
      'ScheduleInterval' => string '40' (length=2)
  2 =>
    array (size=3)
      'BookedDate' => string '2013-08-14' (length=10)
      'BookedTime' => string '1000' (length=4)
      'ScheduleInterval' => string '40' (length=2)
  3 =>
    array (size=3)
      'BookedDate' => string '2013-08-13' (length=10)
      'BookedTime' => string '1040' (length=4)
      'ScheduleInterval' => string '40' (length=2)
  4 =>
    array (size=3)
      'BookedDate' => string '2013-08-13' (length=10)
      'BookedTime' => string '1240' (length=4)
      'ScheduleInterval' => string '40' (length=2)
  5 =>
    array (size=3)
      'BookedDate' => string '2013-08-13' (length=10)
      'BookedTime' => string '1320' (length=4)
      'ScheduleInterval' => string '40' (length=2)
  6 =>
    array (size=3)
      'BookedDate' => string '2013-08-13' (length=10)
      'BookedTime' => string '1440' (length=4)
      'ScheduleInterval' => string '40' (length=2)
  7 =>
    array (size=3)
      'BookedDate' => string '2013-08-13' (length=10)
      'BookedTime' => string '1640' (length=4)
      'ScheduleInterval' => string '40' (length=2)
  8 =>
    array (size=3)
      'BookedDate' => string '2013-08-13' (length=10)
      'BookedTime' => string '1720' (length=4)
      'ScheduleInterval' => string '40' (length=2)
<?php
$i = 0;
foreach ($result as $value) {
		$myarr[$i]['Date'] = $value['BookedDate'];
		$myarr[$i]['Date_unix'] = strtotime($value['BookedDate']);
		$myarr[$i]['Time'] = substr_replace($value['BookedTime'], ':', -2,0);
		$myarr[$i]['Date_time'] = $myarr[$i]['Date'] . ' ' . $myarr[$i]['Time'];
		$myarr[$i]['Date_time_unix'] = strtotime($myarr[$i]['Date_time']);
		$myarr[$i]['Day_number'] = date('N', $myarr[$i]['Date_unix']);
		$myarr[$i]['Day_text'] = date('D', $myarr[$i]['Date_unix']);
		$i++;
} ?>

Code #1

<?php
echo '<table width="700" border="1">';
foreach ($myarr as $event) {
	echo '<tr>';
	$start_time = $monday_time;

	for ($x = 1; $x <= 7; $x++) {
		$hits = 0;
		if ($event['Day_number'] == date('N', $start_time)) {
			echo '<td>' . $event['Time'] . '</td>';
		} else echo '<td>Tom</td>';
		$start_time += 86400;
	}
	echo '</tr>';
}
echo '</tr>';
echo '</table>';
?>

Code #2

<?php
echo '<table width="700" border="1">';
echo '<tr>';

$events = count($myarr);

$dayvar[1] = $monday_time;
$dayvar[2] = $tuesday_time;
$dayvar[3] = $wednesday_time;
$dayvar[4] = $thursday_time;
$dayvar[5] = $friday_time;
$dayvar[6] = $saturday_time;
$dayvar[7] = $sunday_time;

$counter = 0;
$x = 1;
while ($counter < $events) {
$start_time = $monday_time;
	for ($i=1;$i<=7;$i++) {
	if ($x == 8) {
		echo '</tr><tr>';
		$x = 1;
	}
		if (date('N', $dayvar[$i]) == $myarr[$counter]['Day_number']) {
			echo '<td>' . $myarr[$counter]['Time'] . '</td>';	
		} else echo '<td>Tom</td>';
	$x++;
	}
$counter++;
}
echo '</table>';
?>

This is what comes from it.

Tom	Tom	Tom	08:00	Tom	Tom	Tom
Tom	10:00	Tom	Tom	Tom	Tom	Tom
Tom	Tom	10:00	Tom	Tom	Tom	Tom
Tom	10:40	Tom	Tom	Tom	Tom	Tom
Tom	12:40	Tom	Tom	Tom	Tom	Tom
Tom	13:20	Tom	Tom	Tom	Tom	Tom
Tom	14:40	Tom	Tom	Tom	Tom	Tom
Tom	16:40	Tom	Tom	Tom	Tom	Tom
Tom	17:20	Tom	Tom	Tom	Tom	Tom

As you can see row #2 & 3 has the same time event in different days. My wish is to put these on the same line.
Is this possible using tables or should take the approach using DIV instead? (wich seems to be much easier).