Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Fukcja PHP wyświetlająca n kolejnych dni, w widoku kalendarza
noisysomeone
post 11.08.2015, 09:43:06
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
kapslokk
post 11.08.2015, 09:48:21
Post #2





Grupa: Zarejestrowani
Postów: 965
Pomógł: 285
Dołączył: 19.06.2015
Skąd: Warszawa

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


Klasa DateTime ma chyba wszystko czego potrzebujesz. Ale z kalendarzem będziesz musiał powalczyć smile.gif

Ten post edytował kapslokk 11.08.2015, 09:48:58
Go to the top of the page
+Quote Post
grzes999
post 11.08.2015, 10:04:55
Post #3





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

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


Pokombinuj z tym i n apewno ci zadziała

  1. $now = new DateTime();
  2. for($i = 0;$i<10;$i++) {
  3. $next = $now->add(new DateInterval('P'.$i.'D'));
  4. echo $next->format('Y-m-d')."<br/>";
  5. }
Go to the top of the page
+Quote Post
Pyton_000
post 11.08.2015, 10:11:03
Post #4





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


Odpalałeś to? Bo na pewno nie zadziała.

Ten post edytował Pyton_000 11.08.2015, 10:11:17
Go to the top of the page
+Quote Post
grzes999
post 11.08.2015, 15:08:51
Post #5





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

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


@up
To jest tylko podpowiedź jak za takie coś powinien się zabrać smile.gif sam skrypt działa tylko nie do końca tak jak powinien; ale drobna modyfikacja i powinno działać tak jak autor tego oczekuje smile.gif
Go to the top of the page
+Quote Post
noisysomeone
post 12.08.2015, 09:45:35
Post #6





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

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


A jak ułożyć te daty w takiej formie? http://www.cocoondesign.pl/wp-content/uplo...endarz-2014.jpg
Go to the top of the page
+Quote Post
wasyllinio
post 12.08.2015, 21:08:32
Post #7





Grupa: Zarejestrowani
Postów: 20
Pomógł: 0
Dołączył: 6.02.2009

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


dla każdego DateTime'a możesz skorzystać z formatu "N"
http://php.net/manual/en/function.date.php

Dalej już chyba trafisz
Go to the top of the page
+Quote Post
grzes999
post 13.08.2015, 12:39:34
Post #8





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

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


Znalezione w google plus mała modyfikacja 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

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

 



RSS Wersja Lo-Fi Aktualny czas: 12.06.2025 - 22:14