Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Kalendarz
Forum PHP.pl > Forum > Gotowe rozwiązania > Szukam
Mlodycompany
Witam. Chciałbym zrobić kalendarz typu

Kod
Czerwiec      
Nd  Pn  Wt  Sr  Cz  Pt  So  
1    2    3    4    5    6    7
8    9    10   11  12 13   14
15  16   17   18  19 20   21
22  23   24   25  26 27   28
29  30

i aby generowalo coś takiego do każdego miesiąca. Czy jest jakaś funkcja czy poprostu trzeba robic kazdy miesiac osobno?
Gecco
samej funkcji jako takiej do wyswietlenia czegos takiego to nie ma. musisz skorzystac z funkcji date() ta funkcja mozesz pobrac liczbe dni, sprawdz czy np pierwszy dzien miesiaca to czwartek itd, dla innych lat i miesiecy pobieraj wartosci przez get. kiedys cos takiego pisalem jak znajde to wrzuce
Mlodycompany
no własnie chętnie bym gotowca wzioł bo kurcze ciezko mi sie dzisiaj mysli biggrin.gif
marcio
O lol pelnio tego w sieci jest a ty chcesz zeby ktos gotowca dal ktorego mozesz sam znalesc lub napisac ale ogolnie to mozesz to zrobic w js nawet chyba lepiej by bylo
Mlodycompany
no ale ja jsa wcale nie kumam dlatego wole w php chyba ze masz gotowca w js to poprosze
phpion
Czy naprawdę tak ciężko wysilić szare komórki i poszukać samemu na googlach?

Jeśli znasz się na PHP to skorzystaj z tego, co ostatnio napisałem:

Calendar.php:
  1. <?php
  2. class Calendar {
  3. protected $weeks = array();
  4. protected $date;
  5.  
  6. public function __construct($date) {
  7. $this->date = strtotime($date);
  8.  
  9. $this->generate();
  10. }
  11.  
  12. protected function generate() {
  13. $year = date('Y', $this->date);
  14. $month = date('m', $this->date);
  15. $day = date('d', $this->date);
  16.  
  17. $i = 1;
  18. $week = new Calendar_Week();
  19.  
  20. while ($i <= date('t', $this->date)) {
  21. $date = strtotime($year.'-'.$month.'-'.sprintf('%02d', $i));
  22.  
  23. if (date('N', $date) == 1) {
  24. if ($week->getCounter() > 0) {
  25. $this->weeks[] = $week;
  26. }
  27.  
  28. $week = new Calendar_Week();
  29. }
  30.  
  31. $week->setDay(date('N', $date), $i);
  32.  
  33. $i++;
  34. }
  35.  
  36. $this->weeks[] = $week;
  37. }
  38.  
  39. public function getWeeks() {
  40. return $this->weeks;
  41. }
  42. }
  43. ?>


Calendar_Week.php:
  1. <?php
  2. class Calendar_Week {
  3. private $_days;
  4. private $_counter = 0;
  5.  
  6. public function __construct() {
  7. $this->_days = array(
  8. => false,
  9. false,
  10. false,
  11. false,
  12. false,
  13. false,
  14. false
  15. );
  16. }
  17.  
  18. public function setDay($dayOfWeek, $dayOfMonth) {
  19. $this->_days[$dayOfWeek] = $dayOfMonth;
  20. $this->_counter++;
  21. }
  22.  
  23. public function getDay($dayOfWeek) {
  24. return $this->_days[$dayOfWeek];
  25. }
  26.  
  27. public function getDays() {
  28. return $this->_days;
  29. }
  30.  
  31. public function getCounter() {
  32. return $this->_counter;
  33. }
  34. }
  35. ?>


calendar.phtml:
  1. <table id="calendar">
  2. <thead>
  3. <tr>
  4. <th><a href="./?date=<?= date('Y-m', strtotime("-1 month", strtotime($date))) ?>-01">&laquo;</a></th>
  5. <th><a href="./?date=<?= date('Y-m-d', strtotime("-1 day", strtotime($date))) ?>">&lsaquo;</a></th>
  6. <th colspan="3"><?= date('M Y', strtotime($date)) ?></th>
  7. <th><a href="./?date=<?= date('Y-m-d', strtotime("+1 day", strtotime($date))) ?>">&rsaquo;</a></th>
  8. <th><a href="./?date=<?= date('Y-m', strtotime("+1 month", strtotime($date))) ?>-01">&raquo;</a></th>
  9. </tr>
  10. </thead>
  11. <tbody>
  12. <?php foreach ($calendar->getWeeks() as $w): ?>
  13. <tr>
  14. <?php for($i=1; $i<=7; $i++): ?>
  15. <?php if ($w->getDay($i)): ?>
  16. <td<?= $year.'-'.$month.'-'.sprintf('%02d', $w->getDay($i)) == $date ? ' id="currentDay"' : null ?>><a href="./?date=<?php echo $year.'-'.$month.'-'.sprintf('%02d', $w->getDay($i)) ?>"><?= $w->getDay($i) ?></a></td>
  17. <?php else: ?>
  18. <td></td>
  19. <?php endif; ?>
  20. <?php endfor; ?>
  21. </tr>
  22. <?php endforeach; ?>
  23. </tbody>
  24. </table>


Wywołanie:
  1. <?php
  2. $date = date('Y-m-d');
  3. $calendar = new Calendar($date);
  4. $year = date('Y', strtotime($date));
  5. $month = date('m', strtotime($date));
  6. ?>


Have fun!
nevt
nie ten dział, skoro to poszukiwania gotowca, przenoszę.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2024 Invision Power Services, Inc.