Guest User

Untitled

a guest
Aug 28th, 2010
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.42 KB | None | 0 0
  1.  
  2. <?php
  3. date_default_timezone_set('Europe/Helsinki');
  4.  
  5. // Get...
  6. $month = $_POST['ViewMonth'];
  7. if($month == ""){
  8. $month = "01";
  9. }
  10. $year= $_POST['ViewYear'];
  11. if($year == ""){
  12. $year = "2010";
  13. }
  14. // Check for events
  15. $con = mysql_connect("$mysql_host", "mysql_$username", "mysql_$password")
  16. if(!$con){
  17. echo "Error trying to connect to mysql!";
  18. }
  19. $select_db = mysql_select_db("test");
  20. if(!$select_db){
  21. echo "Error trying to select mysql database!";
  22. }
  23. $query = "SELECT FROM calendar"
  24.  
  25. // Controls
  26. ?>
  27. <form action="test.php" method="POST">
  28. Månad: <select name="ViewMonth">
  29. <?php for($i = 1; $i < 13; $i++) { //******added for loop, so you could keep the last selected month.
  30.  
  31.    
  32.  
  33. echo '<option ';
  34.  
  35.    
  36.  
  37. echo ($i == (int)$month) ? 'selected="selected"' : NULL;
  38.  
  39.    
  40.  
  41. echo '>' . $i . '</option>';
  42.  
  43.    
  44.  
  45. }
  46. ?>
  47. </select>
  48. År: <select name="ViewYear">
  49. <?php for($i = 2006; $i < 2015; $i++) { //******added teh for loop, so you could keep the last selected year.
  50.  
  51.    
  52.  
  53. echo '<option ';
  54.  
  55.    
  56.  
  57. echo ($i == (int)$year) ? 'selected="selected"' : NULL;
  58.  
  59.    
  60.  
  61. echo '>' . $i . '</option>';
  62.  
  63.    
  64.  
  65. }
  66. ?>
  67. </select>
  68. <input type="submit" value="Gå">
  69. </form>
  70. <?php
  71.  
  72. //This gets today's date
  73. $date =time () ;
  74.  
  75. //This puts the day, month, and year in seperate variables
  76. $day = date('d', $date) ;
  77. //$month = date('m', $date) ;
  78. //$year = date('Y', $date) ;
  79.  
  80. //Here we generate the first day of the month
  81. $first_day = mktime(0,0,0,$month, 1, $year) ;
  82.  
  83. //This gets us the month name
  84. $title = date('F', $first_day) ;
  85. //*****This line had been deleted, making the switch Useless.
  86. //Here we find out what day of the week the first day of the month falls on $day_of_week = date('D', $first_day) ;
  87.  $day_of_week = date('D',$first_day);
  88.  //Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero
  89.  switch($day_of_week){  //******days re-ordered.
  90.  
  91.  case "Mon": $blank = 0; break;
  92.  case "Tue": $blank = 1; break;
  93.  case "Wed": $blank = 2; break;
  94.  case "Thu": $blank = 3; break;
  95.  case "Fri": $blank = 4; break;
  96.  case "Sat": $blank = 5; break;
  97.  case "Sun": $blank = 6; break;
  98.  }
  99.  
  100.  //We then determine how many days are in the current month
  101.  $days_in_month = cal_days_in_month(0, $month, $year) ;
  102.  
  103.  //Here we start building the table heads
  104.  echo "<table border=1 width=294>";
  105.  echo "<tr><th colspan=7> $title $year </th></tr>";
  106.  //*******Changed echo string to reflect that 1st day is Monday.
  107.  echo "<tr><td width=42>Mån</td><td width=42>Tis</td><td
  108. width=42>Ons</td><td width=42>Tors</td><td width=42>Fre</td><td
  109. width=42>Lör</td><td width=42>Sön</td></tr>";
  110.  
  111.  //This counts the days in the week, up to 7
  112.  $day_count = 1;
  113.  
  114.  echo "<tr>";
  115.  //first we take care of those blank days
  116.  while ( $blank > 0 )
  117.  {
  118.  echo "<td></td>";
  119.  $blank = $blank-1;
  120.  $day_count++;
  121.  }
  122.  
  123.  //sets the first day of the month to 1
  124.  $day_num = 1;
  125.  
  126.  //count up the days, untill we've done all of them in the month
  127.  while ( $day_num <= $days_in_month )
  128.  {
  129.  echo "<td> $day_num </td>";
  130.  $day_num++;
  131.  $day_count++;
  132.  
  133.  //Make sure we start a new row every week
  134.  if ($day_count > 7)
  135.  {
  136.  echo "</tr><tr>";
  137.  $day_count = 1;
  138.  }
  139.  }
  140.  
  141.  //Finaly we finish out the table with some blank details if needed
  142.  while ( $day_count >1 && $day_count <=7 )
  143.  {
  144.  echo "<td> </td>";
  145.  $day_count++;
  146.  }
  147.  echo "</tr></table>";
  148.  ?>
Advertisement
Add Comment
Please, Sign In to add comment