PDA

View Full Version : NOOB Q?=adding events to my php calendar??



fuston05
22 Feb 2010, 10:51 AM
i am continuing to work on this calendar as i am learning so much from studting and mastering each step.. now i would like to add some events. I am NOT wanting to use java or anything else for now, i know this really limits me but i am trying to get php down really well before i move on to java etc.. so, my question is is there another way to link to an event on a particular day other than just linking to a new page to display the events for each day using just php?? i know it could be done alot more professionally with java but as i said i am wanting to learn php for now. ty in advance. :) i am really starting to get this.. thanx to all of you guys helping me out, and the tutorials i am doing. :)
also, this calendar script is an "included" file in my index.php file
here's my script so far:


ini_set('date.timezone', 'America/Indianapolis');

$date = time();

$day = date('j', $date);
$month = date('m', $date);
$year = date('Y', $date);

if (isset($_COOKIE["month"])){
$month = $_COOKIE["month"];
}

if(isset($COOKIE["year"])){
$year = $_COOKIE["year"];
}

$nexty = $year;
$nextm = $month+1;
if($nextm >12){
$nextm = 1;
$nexty = $year+1;
}

$prevy= $year;
$prevm= $month -1;
if($prevm <1){
$prevm = 12;
$prevy = $year-1;
}



$first_day = mktime(0,0,0,$month, 1, $year);

$title = date('F', $first_day);

$day_of_week = date('D', $first_day);

switch($day_of_week){
case "Sun": $blank= 0; break;
case "Mon": $blank= 1; break;
case "Tue": $blank= 2; break;
case "Wed": $blank= 3; break;
case "Thu": $blank= 4; break;
case "Fri": $blank= 5; break;
case "Sat": $blank= 6; break;
}

$days_in_month = cal_days_in_month(0, $month, $year);


echo "<div id =\"calendar\"><table border= \"0\" width= \"300\" height= \"250\">";

echo "<tr>
<td colspan=\"1\">
<a href=\"cal_cook.php?m=$prevm&y=$prevy\"><<</a></td>
<td colspan= \"5\" id=\"calhead\">$title $year</td>
<td colspan= \"1\"><a href=\"cal_cook.php?m=$nextm&y=$nexty\">>></a></td>
</tr>";

echo "<tr>
<td width= \"42\">S</td>
<td width= \"42\">M</td>
<td width= \"42\">T</td>
<td width= \"42\">W</td>
<td width= \"42\">T</td>
<td width= \"42\">F</td>
<td width= \"42\">S</td>
</tr>";

$day_count = 1;

while($blank > 0){
echo "<td>&nbsp;</td>";
$blank = $blank -1;
$day_count++;
}

$day_num = 1;

while($day_num <= $days_in_month){
if($day==$day_num){
echo "<td><span style= \"font-weight:bold; color:#ff0000;\">$day_num</span></td>";
}
else{
echo "<td>$day_num</td>";
}
$day_num++;
$day_count++;

if($day_count > 7){
echo "</tr><tr>";
$day_count=1;
}

}




while($day_count >1 && $day_count <=7)
{
echo "<td>&nbsp;</td>";
$day_count++;
}

echo "</tr></table></div>";

dmcleary
23 Feb 2010, 08:12 AM
Hi fuston05,

You need to understand that PHP is a *server* side language which means that all processing must be done at the server by request - ie a link in this case.

When you move on to JavaScript (I assume you meant JS not Java?) you'll start to unravel AJAX which is the technology you want to implement in order to have seamless calendar (think Google Calendar).

Also, just one note in passing: I would use $_SESSION variables rather than $_COOKIE variables.

I hope that helps and good luck with the project.

Regards,


David