logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Coding & Scripting Corner View previous topic :: View next topic
Reply to topic   Topic: highlighting weekends
Author
fifimtwana



Joined: 24 Feb 2011
Posts: 22

PostPosted: Wed 16 Mar '11 12:17    Post subject: highlighting weekends Reply with quote

hey guys i created a calendar and on each month all the weekends are highlighted with a different colour.

My problem is that august doesnt show its highlights Shocked not sure what i have done wrong...

Here is the code i used below:

<table border=0 width = 1000>
<tr>

<td valign="center"><font size="3" face="bmwtyperegular" color="#666666">
<B>P10 YEAR PLANNER
</td>
<td valign="center"><font size="3" face="bmwtyperegular" color="#666666">
<B>
</td>
</tr>
</table>

<table border=0 width=1000>
<tr>
<td>
<HR NOSHADE size="1" color="#eeeeee">
</td>
</tr>
</table>


<font size="2" color="black"> <B>
<?php
//============================================PHP START================================================//

//===================================Connecting to DB START=========================================//
$mysqluser = 'root';
$mysqlpasswd = '689453';
$mysqlhost = 'localhost';
$mysqlDB = 'p10DB';
mysql_connect($mysqlhost,$mysqluser,$mysqlpasswd);
mysql_select_db($mysqlDB) or die( "Unable to select database");
//===================================Connecting to DB STOP=========================================//
//===================================SQL Query START=========================================//

//while($nt=mysql_fetch_array($result1))
// echo "<option value=$nt[ID]>$nt[Name]</option>";
//echo "</select>";

//===================================SQL Query STOP=========================================//


$START_YEAR = 2010;
$END_YEAR = 2011;

$day_no = 0;
for($yCount = $START_YEAR; $yCount <= $END_YEAR; $yCount++)
{

if($yCount == 2009)
{
$weekend = 3;
}
if($yCount == 2010)
{
$weekend = 4;
}
if($yCount == 2011)
{
$weekend = 5;
}
for($mCount = 1; $mCount <= 12; $mCount++)
{
$new_month = 0;



if($mCount == 1)
{
$no_days = 31;
$display_month = "01";
echo "JANUARY";
$weekend1 = $weekend + 0;
}
if($mCount == 2)
{
$no_days = 28;
$display_month = "02";
echo "FEBRUARY";
$weekend1 = $weekend + 3;

if($yCount == 2010)
{
$weekend1 = $weekend -4;
}
if($yCount == 2011)
{
$weekend1 = $weekend -4;
}
}
if($mCount == 3)
{
$no_days = 31;
$display_month = "03";
echo "MARCH";
$weekend1 = $weekend + 3;

//Month to year calendar that was wrong

if($yCount == 2010)
{
$weekend1 = $weekend -4;
}
if($yCount == 2011)
{
$weekend1 = $weekend -4;
}
}

if($mCount == 4)
{
$no_days = 30;
$display_month = "04";
echo "APRIL";
$weekend1 = $weekend -1;
}
if($mCount == 5)
{
$no_days = 31;
$display_month = "05";
echo "MAY";
$weekend1 = $weekend + 1;
}
if($mCount == 6)
{
$no_days = 30;
$display_month = "06";
echo "JUNE";
$weekend1 = $weekend + -3;
}
if($mCount == 7)
{
$no_days = 31;
$display_month = "07";
echo "JULY";
$weekend1 = $weekend -1;
if($yCount == 2010)
{
$weekend1 = $weekend -4;
}
if($yCount == 2011)
{
$weekend1 = $weekend -5;
}
}

if($mCount == Cool
{
$no_days = 31;
$display_month = "08";
echo "AUGUST";
$weekend1 = $weekend ;

if($yCount == 2010)
{
$weekend1 = $weekend -4;
}
if($yCount == 2011)
{
$weekend1 = $weekend -5;
}
}

if($mCount == 9)
{
$no_days = 30;
$display_month = "09";
echo "SEPTEMBER";
$weekend1 = $weekend -2;
}
if($mCount == 10)
{
$no_days = 31;
$display_month = "10";
echo "OCTOBER";
$weekend1 = $weekend + 0;
}
if($mCount == 11)
{
$no_days = 30;
$display_month = "11";
echo "NOVEMBER";
$weekend1 = $weekend + 3;

if($yCount == 2010)
{
$weekend1 = $weekend -4;
}
if($yCount == 2011)
{
$weekend1 = $weekend -4;
}
}


if($mCount == 12)
{
$no_days = 31;
$display_month = "12";
echo "DECEMBER";
$weekend1 = $weekend -2;
}


echo ' '.$yCount;
?> <BR> <BR>
<TABLE border="0" WIDTH="1000" callpadding="0" cellspacing="0" BORDERCOLOR="#888888">
<TR>
<TD> <font size="1">

<TABLE border="0">
<TR>
<TD width="400" bgcolor="#444444"> <font size="1" color="white"> <B>
TRAINING EVENT
</TD>
<TD width="100" bgcolor="#444444"><font size="1" color="white"> <B>
TRAINER
</TD>
<?PHP

for($dCount = 1; $dCount <= $no_days; $dCount++)
{
?> <TD bgcolor="#444444"><font size="1" color="white"><B> <?PHP
$day_no = $dCount;
if($dCount < 10)
$day_no = '0'.$dCount;
echo $day_no;
?> </TD> <?PHP
}

$filename = "P:\P-1\test\Technical Training Schedule1 2009.txt";
$row = 1;

$handle = fopen("./Technical Training Schedule1 2009.csv", "r");
$x = 0;
while (($data = fgetcsv($handle, 7000, ",")) !== FALSE)
{
$num = count($data);
//echo "<p> $num fields in line $row: <br /></p>\n";
$row++;


$EDATE = $data[2];
$end_D = '20'.$EDATE[4].$EDATE[5].'-'.$EDATE[7].$EDATE[8].'-'.$EDATE[10].$EDATE[11];
$SDATE = $data[1];
$start_D = '20'.$SDATE[4].$SDATE[5].'-'.$SDATE[7].$SDATE[8].'-'.$SDATE[10].$SDATE[11];
$date1 = strtotime($end_D); //(March 21st 2008)
$date2 = strtotime($start_D); //(December 18th 2007)
$date3 = 1 + (($date1 - $date2)/86400);

if(($date3 > 0)&&($date3 < 200))
{


$m = $mCount;
if($mCount < 10)
$m = '0'.$mCount;
$pDate = $yCount.$m;
$tDateE = $end_D[0].$end_D[1].$end_D[2].$end_D[3].$end_D[5].$end_D[6];
$tDateS = $start_D[0].$start_D[1].$start_D[2].$start_D[3].$start_D[5].$start_D[6];
$HR = $data[4];
$HR = strtoupper($HR);
if($HR == "")
$pDate = "ffffff";

if((($pDate == $tDateE)||($pDate == $tDateS))||(($pDate <= $tDateE)&&($pDate >= $tDateS)))

{

if($HR == "CHRIS")
$bgColor = "66aaaa";
if($HR == "WILLEM")
$bgColor = "cc3344";
if($HR == "KOBUS")
$bgColor = "cc99ff";
if($HR == "HEIN")
$bgColor = "ffccff";
if($HR == "CAREL")
$bgColor = "ffee11";
if($HR == "PAUL")
$bgColor = "6699dd";
if($HR == "DEON")
$bgColor = "ffbb33";
if($HR == "ROBYN")
$bgColor = "ffcc99";
if($HR == "LEE")
$bgColor = "33aa44";
if($HR == "SHANE")
$bgColor = "99aaaa";
if($HR == "TDIV")
$bgColor = "966666";
if($HR == "T_DIV")
$bgColor = "44ddcc";
?>
</TR>
<TR>
<TD width="400" bgcolor="#<?PHP echo $bgColor;?>"> <font size="1">
<?PHP echo $data[0];?>
</TD>
<TD width="100" bgcolor="#<?PHP echo $bgColor;?>"> <font size="1">
<?PHP
$HR = $data[4];
$HR = strtoupper($HR);
echo $HR; ?>
</TD>
<?PHP
$T_end_D = $end_D[0].$end_D[1].$end_D[2].$end_D[3].$end_D[5].$end_D[6].$end_D[8].$end_D[9];
$T_start_D = $start_D[0].$start_D[1].$start_D[2].$start_D[3].$start_D[5].$start_D[6].$start_D[8].$start_D[9];
$w_end = $weekend1;
for($dCount = 1; $dCount <= $no_days; $dCount++)
{
$w_end++;

$d = $dCount;
if($dCount < 10)
$d = '0'.$dCount;
$m = $mCount;
if($mCount < 10)
$m = '0'.$mCount;
$test_DATE = $yCount.$m.$d;
if($w_end == 6)
{
?><TD align="center" bgcolor="#999999"><font size="1"><?PHP
}
if($w_end == 7)
{
?><TD align="center" bgcolor="#999999"><font size="1"><?PHP
}

if((($test_DATE > $T_end_D)||($test_DATE < $T_start_D))&&(($w_end <> 6)&&($w_end <> 7)))
{
?><TD align="center" bgcolor="#eeeeee"><font size="1"><?PHP
}

if((($test_DATE <= $T_end_D)&&($test_DATE >= $T_start_D))&&(($w_end <> 6)&&($w_end <> 7)))
{
?><TD align="center" bgcolor="#<?PHP echo $bgColor;?>"><font size="1"><?PHP
echo " ";

}

if($w_end == 7)
{
$w_end = 0;
}

?></TD><?PHP
}
}
}
}
fclose($handle);

?>

</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<BR>
<?PHP
}
}

?>



<TABLE border="1">


<?PHP




?>
</table>


<?PHP

mysql_close();
?>
</body>

</font>
</html>
Back to top
Virsacer



Joined: 16 Jan 2010
Posts: 108
Location: Germany, Darmstadt

PostPosted: Wed 16 Mar '11 22:05    Post subject: Reply with quote

Your code ist way way way too complicated...

PHP has some nice date functions http://www.php.net/manual/en/ref.datetime.php

You should use CSS for the design and also check your HTML output with http://validator.w3.org


I would like to see how your calender should look like.
But since it needs data from a csv file I can not test it.
Can you provide that file?
Back to top
fifimtwana



Joined: 24 Feb 2011
Posts: 22

PostPosted: Thu 17 Mar '11 7:58    Post subject: Reply with quote

The CSV file is done in excel.. How do u attach a file here? Mr. Green
Back to top
Virsacer



Joined: 16 Jan 2010
Posts: 108
Location: Germany, Darmstadt

PostPosted: Thu 17 Mar '11 11:13    Post subject: Reply with quote

You have to upload it to your own domain or a file hosting service...
Back to top
fifimtwana



Joined: 24 Feb 2011
Posts: 22

PostPosted: Fri 18 Mar '11 12:32    Post subject: Reply with quote

its all sorted now.... Thanx for your replies Wink
Back to top


Reply to topic   Topic: highlighting weekends View previous topic :: View next topic
Post new topic   Forum Index -> Coding & Scripting Corner