Leave a comment

Calender In PHP

 <?php
$con = mysql_connect(“localhost”, “root”, “admin”) or die(“Database connection failed: “.mysql_error());
    $conn = mysql_select_db(“balloonz”, $con) or die(“Database selection failed:”.mysql_error());
?>
 <?php
$monthNames = Array(“January”, “February”, “March”, “April”, “May”, “June”, “July”,
“August”, “September”, “October”, “November”, “December”);
?>

<?php
if (!isset($_REQUEST[“month”])) $_REQUEST[“month”] = date(“n”);
if (!isset($_REQUEST[“year”])) $_REQUEST[“year”] = date(“Y”);
?>

<?php
$cMonth = $_REQUEST[“month”];
$cYear = $_REQUEST[“year”];

$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;

if ($prev_month == 0 ) {
    $prev_month = 12;
    $prev_year = $cYear – 1;
}
if ($next_month == 13 ) {
    $next_month = 1;
    $next_year = $cYear + 1;
}
?>
<style type=”text/css”>
td{
    border:1px solid #4899D1;
    }
a{
    text-decoration:none;}    
h2{
    font-family:Arial, Helvetica, sans-serif;
    font-size:10px;
    font-weight:bold;
    color:#F00;
    }    
h3{
    font-family:Arial, Helvetica, sans-serif;
    font-size:10px;
    font-weight:bold;    
    color:#090;
    }    

</style>

<table width=”200″>
<tr align=”center”>
<td bgcolor=”#4899D1″ style=”color:#FFFFFF”>
<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td width=”50%” align=”left”>&nbsp;&nbsp;<a href=”<?php echo $_SERVER[“PHP_SELF”] . “?month=”. $prev_month . “&year=” . $prev_year; ?>” style=”color:#fff”>Previous</a></td>
<td width=”50%” align=”right”><a href=”<?php echo $_SERVER[“PHP_SELF”] . “?month=”. $next_month . “&year=” . $next_year; ?>” style=”color:#fff”>Next</a>&nbsp;&nbsp;</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align=”center”>
<table width=”100%” border=”0″ cellpadding=”2″ cellspacing=”2″>
<tr align=”center”>
<td colspan=”7″ bgcolor=”#4899D1″ style=”color:#FFFFFF”><strong><?php echo $monthNames[$cMonth-1].’ ‘.$cYear; ?></strong></td>
</tr>
<tr>
<td align=”center” bgcolor=”#4899D1″ style=”color:#FFFFFF”><strong>S</strong></td>
<td align=”center” bgcolor=”#4899D1″ style=”color:#FFFFFF”><strong>M</strong></td>
<td align=”center” bgcolor=”#4899D1″ style=”color:#FFFFFF”><strong>T</strong></td>
<td align=”center” bgcolor=”#4899D1″ style=”color:#FFFFFF”><strong>W</strong></td>
<td align=”center” bgcolor=”#4899D1″ style=”color:#FFFFFF”><strong>T</strong></td>
<td align=”center” bgcolor=”#4899D1″ style=”color:#FFFFFF”><strong>F</strong></td>
<td align=”center” bgcolor=”#4899D1″ style=”color:#FFFFFF”><strong>S</strong></td>
</tr>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date(“t”,$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth[‘wday’];
$tmp=$cYear.$cMonth;

for ($i=0; $i<($maxday+$startday); $i++)
 {
    if(($i % 7) == 0 )
    {
    echo “<tr>\n”;
    }
    if($i < $startday)
    {
     echo “<td></td>\n”;

    }
    else
    {
    $tmp2=$tmp.($i – $startday + 1);
    $query = “SELECT * FROM calender WHERE opendate”;//check function
    $inquery = mysql_query($query);
    while($values = mysql_fetch_array($inquery)){
    $rows = $values[‘opendate’];
    }
        ?>
<td height=”20″ align=”center” valign=”middle”>
<a href=”?<?php if($rows == $tmp2){ echo “closedate”;}else{echo “opendate”;}?>=<?php echo $cYear.$cMonth.($i – $startday + 1);?>”><?php echo “<h3>”.($i – $startday + 1).”<h3>” ;?></a></td>
<?php

    }
    if(($i % 7) == 6 )
    {
    echo “</tr>\n”;
    }

}//foreach

?>
</table>
</td>
</tr>
</table>
<?php
$open = $_GET[‘opendate’];

    $sql = “SELECT * FROM calender WHERE opendate=’$open'”;
    $num = mysql_num_rows(mysql_query($sql));

if($num != ”){
    if($num){
        echo “”;
        }
    else{
    $mysql = “INSERT INTO calender(opendate) VALUES(‘$open’)”;
    mysql_query($mysql) or die(mysql_error());
    }
    }//num if
else{
        $mysql = “INSERT INTO calender(opendate) VALUES(‘$open’)”;
        mysql_query($mysql) or die(mysql_error());
    }//num else
 ?>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: