petri111 Posted June 2, 2010 Share Posted June 2, 2010 Hi, Sorry my bad english, if not understanding something I clear case more. I would like to made a calendar which continue automatically when old year end and new year start, how could I made that kind of calendar? This is a linear full year calendar. I mean: M T W T F S S M T W T F S S M T W T F S S November 2010 1 2 3 4 5 6 7 8 9 10 11 12 13 14... December 2010 1 2 3 4 5 6 7 8 9 10 11 12 13 14... January 2011 1 2 3 4 5 6 7 8 9 10 11 12 13 14... February 2011 1 2 3 4 5 6 7 8 9 10 11 12 13 14... March 2011 and so on... I have a little bit of code made, but I don't know how the calendar understand when its change year. Here is the code below what I made now. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//FI" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fi" lang="fi"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15" /> <title>Linear Calendar</title> <style type="text/css" media="all"> body { font-family:"Calibri"; color:#009; } .thisDay { background:#FFC; color:red; } table { border-collapse:collapse; border:1px #009 solid; } td { height:20px; vertical-align:top; text-align:center; width:30px; border:1px #009 solid; } th{ height:30px; width:30px; } .dday:hover { background:#9F0; border-color:#000; } .day6 { background:#ECECFF; } .day7 { background:#E2E2EB; } .kkNimi { text-align:left; vertical-align:middle; } .kkNimi div { padding-left:5px; padding-right:5px; width:160px; } .days{ background:#DDDEDE; } </style> </head> <body> <table width="80%" border="1" cellspacing="0" cellpadding="0"> [code=php:0] <?php $password=""; $user="root"; $host="localhost"; $yhteys=mysql_connect($host, $user, $password) or die(mysql_error()); mysql_select_db("lincal",$yhteys) or die(mysql_error()); $DaysinPage = 36; $dDay = 1; if (isset($_POST['year'])) { $year = $_POST['year']; } else { $year = date ('Y'); } function setYear ($year) { // Check year if (is_numeric ($year) && $year % 1 == 0 && $year > 2010 && $year < 2038) $this -> year = $year; else $this -> year = date ('Y'); return true; } if((isset($_GET['d']))?$dDay=$_GET['d']:$dDay = date("d")); if((isset($_GET['m']))?$month=$_GET['m']:$month = date("n")); if((isset($_GET['y']))?$year=$_GET['y']:$year = date("n")); echo "<tr>\r\n"; echo "<th></th>"; // blank header to compensate for row labels for ($i=1;$i<=5;$i++) // do this 5 times... echo "<th>Ma</th><th>Ti</th><th>Ke</th><th>To</th><th>Pe</th><th>La</th><th>Su</th>\r\n"; echo "<th>Ma</th><th>Ti</th>\r\n"; // if the first falls on Sat, we could need 37 boxes echo "</tr>\r\n"; $months=array(); $months[1]="Jan"; $months[2]='Feb'; $months[3]='Mar'; $months[4]='Apr'; $months[5]='May'; $months[6]='Jun'; $months[7]='Jul'; $months[8]='Aug'; $months[9]='Sep'; $months[10]='Oct'; $months[11]='Nov'; $months[12]="Dec"; $months[13]='Jan'; $months[14]='Feb'; $months[15]='Mar'; $months[16]='Apr'; $months[17]='May'; $months[18]='Jun'; $months[19]='Jul'; $months[20]='Aug'; $months[21]='Sep'; $months[22]='Oct'; $months[23]='Nov'; $months[24]="Dec"; $days_of_month=array(); $days_of_month[1]=31; if (date("Y")%4==0) $days_of_month[2]=29; else $days_of_month[2]=28; $days_of_month[3]=31; $days_of_month[4]=30; $days_of_month[5]=31; $days_of_month[6]=30; $days_of_month[7]=31; $days_of_month[8]=31; $days_of_month[9]=30; $days_of_month[10]=31; $days_of_month[11]=30; $days_of_month[12]=31; $days_of_month[13] =31; if (date("Y")%4==0) $days_of_month[14]=29; else $days_of_month[14]=28; $days_of_month[15]=31; $days_of_month[16]=30; $days_of_month[17]=31; $days_of_month[18]=30; $days_of_month[19]=31; $days_of_month[20]=31; $days_of_month[21]=30; $days_of_month[22]=31; $days_of_month[23]=30; $days_of_month[24]=31; $first_of_month=array(); for ($i=6;$i<=17;$i++) // do this for each of the 12 months { $timestamp=strtotime($months[$i]." 0 ".$year); $first_of_month[$i]=date("w",$timestamp); // day of the week as a number (0-6) } $year=date("Y"); $dDay=date("j"); $month=date("n"); $next = $year + 1; $months = array("Tammikuu $year", "Helmikuu $year", "Maaliskuu $year", "Huhtikuu $year", "Toukokuu $year", "Kesäkuu $year", "Heinäkuu $year", "Elokuu $year", "Syyskuu $year", "Lokakuu $year", "Marraskuu $year", "Joulukuu $year", "Tammikuu $next", "Helmikuu $next", "Maaliskuu $next", "Huhtikuu $next", "Toukokuu $next", "Kesäkuu $next", "Heinäkuu $next", "Elokuu $next", "Syyskuu $next", "Lokakuu $next", "Marraskuu $next", "Joulukuu $next"); for($i=6;$i<=17;$i++) { echo "<tr><td class='kkNimi'><div>".$months[$i-1]."</div></td>"; if ($i<$month) // if the month is passed... { for ($j=1;$j<=$DaysinPage;$j++) echo "<td> </td>"; } // end if($i<$month) elseif ($i>$month) // month is in the future { $counter=0; // count of up to 37 day blocks for ($j=1;$j<=$first_of_month[$i];$j++) // number of blank spaces before... { echo "<td> </td>"; $counter++; // increment counter } for ($j=1;$j<=$days_of_month[$i];$j++) // number of date boxes { echo "<td>".$j."</td>"; $counter++; } for ($j=1;$j<=($DaysinPage-$counter);$j++) // end boxes { echo "<td> </td>"; } } // end elseif ($i>$month) else // current month { $counter=0; for ($j=1;$j<=($first_of_month[$i]+$dDay-1);$j++) // preceding blanks { echo "<td></td>"; $counter++; } echo "<td><font color=\"red\">".$dDay."</font></td>"; // today's day in red $counter++; for ($j=$dDay+1;$j<=$days_of_month[$i];$j++) //remaining days of month { echo "<td>".$j."</td>"; $counter++; } for ($j=1;$j<=($DaysinPage-$counter);$j++) // remaining blanks { echo "<td></td>"; } //echo "\r\n"; // line break } //end else -- current month }// end of for($i=1;$i<=12;$i++) echo "</table>"; function echoSelectDate ($prefix, $date, $disabled = false, $onchange = false) { $r = ''; $selected = array_reverse (explode ('-', $date)); $selects = array ( array ( 'name' => 'D', 'start' => 1, 'end' => 31 ), array ( 'name' => 'M', 'start' => 1, 'end' => 12 ), array ( 'name' => 'Y', 'start' => 2010, 'end' => 2037 ) ); for ($i = 0; $i < 3; $i ++) { $r .= '<select name="' . $prefix . $selects[$i]['name'] . '" id="' . $prefix . $selects[$i]['name'] . '" size="1"'; if ($disabled) $r .= ' disabled="disabled"'; if ($onchange) $r .= ' onchange="' . $onchange . '"'; $r .= '>'; for ($j = $selects[$i]['start']; $j <= $selects[$i]['end']; $j ++) { $r .= '<option value="' . $j . '"'; if ($j == $selected[$i]) $r .= ' selected="selected"'; $r .= '>' . $j . '</option>'; } $r .= '</select>'; } return $r; } mysql_close($yhteys) ?> </table> </body> </html> [/code] Thanks for advance for help. -Petri Quote Link to comment https://forums.phpfreaks.com/topic/203625-calendar-problem/ Share on other sites More sharing options...
ram4nd Posted June 2, 2010 Share Posted June 2, 2010 there is a thing called jquery ui that might help you check it out, and it JavaScript by the way Quote Link to comment https://forums.phpfreaks.com/topic/203625-calendar-problem/#findComment-1066590 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.