I am trying to create a working calendar that allows for you to click on the days date and info about that date would be pulled from mysql, based on the date clicked. Here is the code I have so far, which works as a basic calendar, but I cannot figure out how to simply and dynamically grab from mysql based on the date clicked....
So, any help is appreciated...Hopefully this is enough info!!!
<?
/*-----------------------------------------------------------|
| My PHP Calendar |
| Written by Amy Parscal |
|-----------------------------------------------------------*/
/*php code*/
$month = (!$month) ? date("n",mktime()) : "$month"; /*if $month is not set, get current time
otherwise, use $month value*/
$year = (!$year) ? date("Y",mktime()) : "$year"; /*if $year is not set, get current time
otherwise, use $year value*/
$thisday = date("j"); //todays day of the month
if ((!$month) || (!$year))
{
$month = date("n",mktime());
$year = date("Y",mktime());
}
$todays_date = date("F j, Y");
$current_time = date("g:i a");
$offset = date("w", mktime(0, 0, 0, $month, 1, $year)); // determines the blank cell offset
// based on the 1st of the month
$month_title = date("F", mktime(0, 0, 0, $month, $thisday, $year));
$day_titles = array('S', 'M', 'T', 'W', 'T', 'F', 'S'); //An array of all the weeks by name
$month_days = date("t", mktime(0, 0, 0, $month, $thisday, $year));
/*mysql queries*/
$host="your_host";
$user="user";
$pass="pass";
$db="calendar";
mysql_connect($host,$user,$pass);
mysql_select_db($db);
$string = "SELECT * FROM dates WHERE date_when='";
if(!$day){
$string .= date("Y-m-d", mktime(0, 0, 0, $month, $thisday, $year));
}
else{
$string .= date("Y-m-d", mktime(0, 0, 0, $month, $day, $year));
}
$string .="'";
$query = mysql_query($string);
if(!$query){
echo("Can't retrieve data Mysql error message for query " . mysql_error());
exit();
}
$date = mysql_fetch_array($query);
/*Begin printing HTML*/
?>
<html>
<head>
<title>My Calendar</title>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<style>
body {
color: black;
font-family: Verdana, Tahoma, Arial;
font-size: 9pt;
background-color: gray }
table {
border: solid 1pt green }
td {
color: black;
font-family: Verdana, Tahoma, Arial;
font-size: 8pt;
font-weight: bold;
background-color: gray }
th {
color: black;
font-family: Verdana, Tahoma, Arial;
font-size: 8pt;
background-color: green;
border: solid 1pt black }
.border {
border: solid 1pt green }
a {
color: green;
text-decoration: none }
a:hover {
color: black;
text-decoration: none}
</style>
</head>
<body class="body">
<table border="0" cellspacing="10" cellpadding="0">
<tr>
<td>
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<td><a href="<? echo $SCRIPT_NAME ?>?month=<?=(($month - 1) < 1) ? 12 : $month - 1 ?>&year=<?=(($month - 1) < 1) ? $year - 1 : $year ?>"><<</a></td>
<td colspan="5" align="center"><? echo $month_title . ' ' . $year ?></td>
<td><a href="<? echo $SCRIPT_NAME ?>?month=<?=(($month + 1) > 12) ? 1 : $month + 1 ?>&year=<?=(($month + 1) > 12) ? $year + 1 : $year ?>">>></a></td>
</tr>
<tr>
<?
for($i = 0; $i < 7; $i++)
?>
<th><? echo $day_titles[$i] ?></th>
<?
//begin printing blank offset cells
?>
<tr>
<?
if($offset > 0)
echo str_repeat('<td class="border"> </td>', $offset);
//begin printing days
for($day = 1; $day <= $month_days; $day++){ ?>
<td class="border"><a href="<? echo $SCRIPT_NAME . '?month=' . $month . '&year=' . $year . '&date_when=' . date("Y-m-d", mktime(0, 0, 0, $month, $day, $year)); ?>"><? echo $day ?></a></td>
<?
$offset++;
//end first row, begin rest of rows
if($offset > 6){
$offset = 0;
?></tr>
<?
if($day < $month_days)
?>
<tr>
<?
}
}
//begin printing blank cells at end of table
if($offset > 0)
$offset = 7 - $offset;
if($offset > 0)
echo str_repeat( '<td class="border"> </td>', $offset );
/* end the table */
?>
</td>
</table>
</td>
<td><textarea name="description" rows="8" cols="40"><? echo $date["2"] ?></textarea></td>
</tr>
</table>
<?
//to test what the query is doing
echo $string;
?>