Hi all,
I'm newbie in php and I wondering if anyone can help me. Problem is how I get weekend table cell. Sa and su should be different color than other day cells in my calendar.
Here is the PHP code:
<style type="text/css">
.start{ background-image: url(alku1.gif);
background-repeat: no-repeat;
background-position: top left}
.end{ background-image: url(loppu1.gif);
background-repeat: no-repeat;
background-position: top left
}
.empties { background-image: url(green.gif);
background-repeat: no-repeat;
background-position: top left
}
</style>
</head>
<body>
<?php
setlocale(LC_TIME, "fin");
$dbuser="root";
$dbpass="";
$host="localhost";
$yhteys=mysql_connect($host, $dbuser, $dbpass) or die(mysql_error());
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("lincal", $conn);
$today = date('Y-n-j');
$action = mysql_query("SELECT * FROM actions WHERE start1 >= '$today'", $conn) or die("Kysely ei onnistunut:". mysql_error());
$actionlist = array();
while ($row = mysql_fetch_array($action)) {
$start = strtotime($row['start1']);
$end = strtotime($row['end1']);
$actionlist[] = array($start, $end);
}
$month = date('n');
$year = date('Y');
$day = date('j');
echo '<table width="100%" border="2px #009 solid; cellspacing="10" cellpadding="0" style="text-align: center">';
echo "<tr>";
echo "<th>month</th>";
for ($i=1;$i<=5;$i++)
//these are weekdays, mo,tu,we,th,fr,sa,su..
echo '<th style="width: 25px;">Ma</th><th style="width: 25px;">Ti</th><th style="width: 25px;">Ke</th><th style="width: 25px;">To</th><th style="width: 25px;">Pe</th><th style="width: 25px;" bgcolor= "#ECECFF">La</th><th style="width: 25px;" bgcolor= "#E2E2EB">Su</th>';
echo '<th style="width: 25px;">Ma</th><th style="width: 25px;">Ti</th>';
echo '<tr>';
for ($i=0; $i<12; $i++) {
$timestamp = mktime(0,0,0,$month+$i,1,$year);
$dayofweek = date('w', $timestamp);
$amountofdays = date('t', $timestamp);
$empties = $dayofweek-1;
echo '<td style=\"width: 20px; text-align: center;\" bgcolor="#FEFEFE">'.strftime("%B %Y", $timestamp).'</td>';
if ($dayofweek == 0) $empties = 6;
$empties--;
for ($j=-1*$empties; $j<=$amountofdays; $j++) {
$thisDay = mktime(0,0,0,$month+$i,$j,$year);
if ($j == date('j') && $i == 0) {
echo '<td bgcolor= "yellow" span style="color: red;" />';
} else {
$action = false;
foreach ($actionlist as $tl) {
if ($tl[0] <= $thisDay && $tl[1] >= $thisDay) $action = true;
}
if ($action == true){
echo '<td bgcolor="red" />';
} elseif ($start != $action){
echo '<td class="start" />';
} elseif ($end == $action) {
echo '<td class="end" />';
} else {
echo '<td bgcolor="#91CD92" />';
}
}
if ($j>0 && ($i>0 || $j>=date('j'))) echo $j;
else echo '<class="empties" />';
echo '</td>';
}
echo '</tr>';
}
echo '</table>';
mysql_close($conn);
?>
Help me, please. Thanks for advance.