Posted By

tylerhall on 11/30/-1


Tagged

month view table mini


Versions (?)

Who likes this?

13 people have marked this snippet as a favorite

luman
meth
topherchris
mdavie
blakeb
dmarten
noname
hudge
willcodeforfood
marteki
blackabee
nb109
dantreacy


Month Table


 / Published in: PHP
 

  1. function minimonth($d = "", $m = "", $y = "")
  2. {
  3. if(empty($d)) $d = date("j");
  4. if(empty($m)) $m = date("m");
  5. if(empty($y)) $y = date("Y");
  6. $today = mktime(0, 0, 0, $m, $d, $y);
  7. $first = mktime(0, 0, 0, $m, 1, $y);
  8.  
  9. $prev_month = date("n", strtotime("-1 month", $today));
  10. $prev_year = date("Y", strtotime("-1 month", $today));
  11. $next_month = date("n", strtotime("+1 month", $today));
  12. $next_year = date("Y", strtotime("+1 month", $today));
  13.  
  14. $caption = date("F Y", $today);
  15.  
  16. $out = "<table id='minimonth' cellspacing='0'>";
  17. $out .= "<tr><td class='caption'><a href='#' onclick='cd($prev_month, $prev_year)'>«</a></td><td class='caption' colspan='5'>$caption</td><td><a href='#' onclick='cd($next_month, $next_year)'>»</a></td></tr>";
  18. $out .= "<tr class='week'><td>S</td><td>M</td><td>T</td><td>W</td><td>T</td><td>F</td><td>S</td></tr>";
  19.  
  20. $w = date("w", $first);
  21. if($w > 0)
  22. {
  23. $out .= "<tr>";
  24. for($i = 0; $i < $w; $i++) $out .= "<td></td>";
  25. }
  26.  
  27. for($i = 1; $i <= date("t", $today); $i++)
  28. {
  29. if(date("w", mktime(0, 0, 0, $m, $i, $y)) == 0) $out .= "<tr>";
  30. $out .= "<td id='d$i' class='day'><a href='#' onclick='pick($i)'>$i</a></td>";
  31. if(date("w", mktime(0, 0, 0, $m, $i, $y)) == 6) $out .= "</tr>";
  32. }
  33.  
  34. $w = date("w", mktime(0, 0, 0, $m, $i - 1, $y));
  35. for($i = $w; $i < 6; $i++) $out .= "<td></td>";
  36.  
  37. $out .= "</tr></table>";
  38.  
  39. echo $out;
  40. }

Report this snippet  

You need to login to post a comment.