nita Posted April 6, 2008 Share Posted April 6, 2008 Hi I have small problem with layout of calendar. All seems to work fine. Script bellow prints out all the days in 1 line and that was fine until now, i would like to have it in real sort of calendar form. Could you help me please to split days in 7 columns, including blank spaces. I seen some similar scripts on the net, but i cant get it all up together. Here is the code <?php function calendar($file){ if((isset($_GET['d']))?$day=$_GET['d']:$day = date("d")); if((isset($_GET['m']))?$month=$_GET['m']:$month = date("m")); if((isset($_GET['y']))?$year=$_GET['y']:$year = date("Y")); $months_days = array("31","28","31","30","31","30","31","31", "30","31","30","31"); $months_name = array("January","Febebruary","March","April","May","June","July", "Augoust","September","October","November","December"); $days_array = array("Mon","Tue","Wed","Thu","Fri","Sat","Sun"); //removes the 0 from start of month - can't find array key with 0 if(strlen($month)==1){ $month= str_replace("0","",$month); } else{ $month=$month; } //reset month to the array key match (array starts at 0) $month= $month-1; //find the days in the month $days_in_month = $months_days[$month]; //And convert the month number to name $month_name = $months_name[$month]; //$m is used to find month $m = $month+1; //find the first day of the month $time = date("M D Y H:i:s", mktime(0, 0, 0, $m, 1, $year)); $first_day = explode(" ",$time); $time = $first_day[1]; //create the links to next and previous months $next = $month+2; $x = $year; //if month is 13 then new year if($next==13){ $next=1; $x = $x+1; } $prev = $month; $y = $year; //if month is 0, then previous year if($prev==0){ $prev=12; $y=$y-1; } //Build the calendar // $calendar .=' <table border="0" cellspacing="0" cellpadding="5"> <tr> <td class="menumanhead"><a href="'.$file.'?m='.$prev.'&y='.$y.'&d='.$day.'"><<</a></td> <td colspan="5"><span class="menumanhead">'.$month_name.' '.$year.'</span></td> <td class="menumanhead"><a href="'.$file.'?m='.$next.'&y='.$x.'&d='.$day.'">>></a></td> </tr> <tr> <td>M</td> <td>T</td> <td>W</td> <td>T</td> <td>F</td> <td>S</td> <td>S</td></tr> </table> '; //checks for leap years and add 1 to February if(($year % 4 =="") && ($month==1)){ $days_in_month=$days_in_month+1; } else{ $days_in_month=$days_in_month; } $new_time=""; //find how many blank spaces at beginning of the month foreach($days_array as $key=>$value){ if($value == $time){ $new_time .= $key+1; } else{ $new_time .=""; } } //loop through the days in the month for($k=1;$k<($days_in_month+$new_time);$k++){ //blank space if($k<$new_time){ $calendar.=' - '; continue; } //start the actual days $n = $k-$new_time+1; if($n==$day){ $calendar .= '<b><a href="availability_manage.php?m='.$m.'&y='.$y.'&d='.$n.'">'.$n.'</a></b> '; } else{ $calendar .= '<a href="availability_manage.php?m='.$m.'&y='.$y.'&d='.$n.'">'.$n.'</a> '; } } return($calendar); } ?> Thank you very much for your help in Advance Nita Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.