Event calender hjælpe
Mit problem er at, jeg kan godt få kalenderen til at virke men lige så snart jeg skal ha en dato ind det rigtige sted med en foreach knalder min kalender bare helt ud og går amok, det ser ud som om den laver en ny <td> for event der er, datoeren rammer rigtigt men den laver bare for mange ny <td>Jeg ved 100% det noget med mine loops at gøre der hvor jeg skal bygge selve kalenderen men kan simpelthen, finde på en anden måde jeg skulle gøre det på
http://pastebin.com/d1107241d <- Kildekode
eller her:
<?php
class Calender {
var $today;
var $first_day;
var $last_day;
var $html;
var $weeks;
var $fullWeeks;
//************ CSS
var $table_id;
var $th_style;
var $td_style;
var $week_style;
var $blank_field;
//************ END
function createHeader()
{
mysql_connect("localhost","root","")or die(mysql_error());
mysql_select_db("leekseek");
$this->today = getdate();
$this->first_day = getdate(mktime(0,0,0,$this->today['mon'],1,$this->today['year']));
$this->last_day = getdate(mktime(0,0,0,$this->today['mon']+1,0,$this->today['year']));
$this->table_id = 'id="calender_css"';
$this->th_style = 'class="th_head"';
$this->week_style = 'class="week"';
$this->blank_field = 'class="th_body_blank"';
$this->td_style = 'class="th_body"';
$this->weeks = array("Mon","Tue","Wed","Thu","Fri","Sat","Sun");
$this->html .= "<table ".$this->table_id." border='1' cellpadding='0' cellspacing='0'>" . "\n";
$this->html .= "<tr>" . "\n";
$this->html .= '<th colspan="7" '.$this->th_style.'>'. $this->today['month'] .' '. $this->today['year'] .'</th>' . "\n";
$this->html .= "</tr>" . "\n";
$this->html .= "<tr>" . "\n";
foreach($this->weeks as $showWeeks)
{
$this->html .= "\t". '<th ' .$this->week_style. '><p>'. $showWeeks .'</p></td>'. "\n";
}
$this->html .= "</tr>\n";
}
function createBody()
{
$this->createHeader();
$this->html .= "<tr>\n";
//CREATING THE BLANKS FIELDS
for($i=1;$i<$this->first_day['wday'];$i++)
{
$this->html .= "<td ". $this->blank_field . "></td>\n";
}
$dayNum = 0;
for($i=$this->first_day['wday']; $i<=7; $i++)
{
$dayNum++;
$this->html .= "<td ". $this->td_style .">". $dayNum ."</td>\n";
}
$this->html .= "</tr>\n";
$sql = mysql_query("SELECT * FROM `calender` WHERE `month` = {$this->today['mon']} AND `year` = {$this->today['year']}")or die(mysql_error());
while($data_query = mysql_fetch_assoc($sql))
{
$array[] = array("Day" => $data_query['day']);
}
//FILLING IN THE LAST OF THE MONTH
$this->fullWeeks = floor(($this->last_day['mday']-$dayNum)/7);
for($i=0; $i < $this->fullWeeks; $i++)
{
$this->html .= "<tr>\n";
for($j=0; $j < 7; $j++)
{
$dayNum++
foreach($array as $events)
{
if($dayNum == $events['Day'])
{
$this->html .= "<td ".$this->td_style.">". $dayNum . "<br /> event is here</td>";
}
else
{
$this->html .= "<td ".$this->td_style.">". $dayNum . "<br /> No events</td>";
}
}
}
$this->html .= "</tr>\n";
}
if($dayNum < $this->last_day['mday'])
{
$this->html .= "<tr>\n";
for($i=0; $i < 7; $i++)
{
$dayNum++;
if($dayNum <= $this->last_day['mday'])
{
$this->html .= "<td ".$this->blank_field."></td>";
}
else
{
$this->html .= "<td ".$this->blank_field."></td>";
}
}
$this->html .= "</tr>\n";
}
}
function createFooter()
{
$this->createBody();
$this->html .= "</table>";
return $this->html;
}
}
$c = new Calender;
echo $c->createFooter();
?>