Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Fukcja PHP wyświetlająca n kolejnych dni, w widoku kalendarza
noisysomeone
post
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 4.05.2009

Ostrzeżenie: (0%)
-----


Hej

Czy istnieje jakaś gotowa funkcja która pobiera:
-ilość dni
-datę np. bieżącą

a następnie wyświetla n kolejnych dni od podanej daty w formie (widoku) kalendarza? Szukałem w sieci i niestety nie znalazłem nic co mógłbym ze swoją wiedzą na temat PHP dostosować do swoich potrzeb.

Jarek
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
grzes999
post
Post #2





Grupa: Zarejestrowani
Postów: 305
Pomógł: 29
Dołączył: 5.07.2011

Ostrzeżenie: (0%)
-----


Znalezione w google plus mała modyfikacja (IMG:style_emoticons/default/smile.gif) zostawiam dla potomnych

  1. function draw_calendar($month,$year){
  2.  
  3. $calendar = "<div style='display:inline-block; margin: 10px;'>".date('F Y',mktime(0,0,0,$month,1,$year));
  4. /* draw table */
  5. $calendar .= '<table cellpadding="5" cellspacing="0" border= "0" class="calendar">';
  6.  
  7. /* table headings */
  8. $headings = array('Nd','Pn','Wt','Śr','Czw','Pt','So');
  9. $calendar.= '<tr class="calendar-row"><td class="calendar-day-head">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>';
  10.  
  11. /* days and weeks vars now ... */
  12. $running_day = date('w',mktime(0,0,0,$month,1,$year));
  13. $days_in_month = date('t',mktime(0,0,0,$month,1,$year));
  14. $days_in_this_week = 1;
  15. $day_counter = 0;
  16. $dates_array = array();
  17.  
  18. /* row for week one */
  19. $calendar.= '<tr class="calendar-row" style="text-align:center;">';
  20.  
  21. /* print "blank" days until the first of the current week */
  22. for($x = 0; $x < $running_day; $x++):
  23. $calendar.= '<td class="calendar-day-np"> </td>';
  24. $days_in_this_week++;
  25. endfor;
  26.  
  27. /* keep going with days.... */
  28. for($list_day = 1; $list_day <= $days_in_month; $list_day++):
  29. $calendar.= '<td class="calendar-day">';
  30. /* add in the day number */
  31. $calendar.= '<div class="day-number">'.$list_day.'</div>';
  32.  
  33. /** QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !! IF MATCHES FOUND, PRINT THEM !! **/
  34. $calendar.= str_repeat('<p> </p>',2);
  35.  
  36. $calendar.= '</td>';
  37. if($running_day == 6):
  38. $calendar.= '</tr>';
  39. if(($day_counter+1) != $days_in_month):
  40. $calendar.= '<tr class="calendar-row">';
  41. endif;
  42. $running_day = -1;
  43. $days_in_this_week = 0;
  44. endif;
  45. $days_in_this_week++; $running_day++; $day_counter++;
  46. endfor;
  47.  
  48. /* finish the rest of the days in the week */
  49. if($days_in_this_week < 8):
  50. for($x = 1; $x <= (8 - $days_in_this_week); $x++):
  51. $calendar.= '<td class="calendar-day-np"> </td>';
  52. endfor;
  53. endif;
  54.  
  55. /* final row */
  56. $calendar.= '</tr>';
  57.  
  58. /* end the table */
  59. $calendar.= '</table>';
  60.  
  61. /* all done, return result */
  62. return $calendar."</div>";
  63. }
  64. for($i=1;$i<=12;$i++) {
  65. echo draw_calendar($i,2015);
  66. }
  67.  
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 17.10.2025 - 16:45