Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Kalendarz
Mlodycompany
post
Post #1





Grupa: Zarejestrowani
Postów: 910
Pomógł: 44
Dołączył: 20.02.2008
Skąd: Łódź

Ostrzeżenie: (20%)
X----


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?

Ten post edytował Mlodycompany 7.06.2008, 12:51:50
Go to the top of the page
+Quote Post
Gecco
post
Post #2





Grupa: Zarejestrowani
Postów: 23
Pomógł: 4
Dołączył: 22.10.2006

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


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
Go to the top of the page
+Quote Post
Mlodycompany
post
Post #3





Grupa: Zarejestrowani
Postów: 910
Pomógł: 44
Dołączył: 20.02.2008
Skąd: Łódź

Ostrzeżenie: (20%)
X----


no własnie chętnie bym gotowca wzioł bo kurcze ciezko mi sie dzisiaj mysli (IMG:http://forum.php.pl/style_emoticons/default/biggrin.gif)
Go to the top of the page
+Quote Post
marcio
post
Post #4





Grupa: Zarejestrowani
Postów: 2 291
Pomógł: 156
Dołączył: 23.09.2007
Skąd: ITALY-MILAN

Ostrzeżenie: (10%)
X----


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
Go to the top of the page
+Quote Post
Mlodycompany
post
Post #5





Grupa: Zarejestrowani
Postów: 910
Pomógł: 44
Dołączył: 20.02.2008
Skąd: Łódź

Ostrzeżenie: (20%)
X----


no ale ja jsa wcale nie kumam dlatego wole w php chyba ze masz gotowca w js to poprosze
Go to the top of the page
+Quote Post
phpion
post
Post #6





Grupa: Moderatorzy
Postów: 6 072
Pomógł: 861
Dołączył: 10.12.2003
Skąd: Dąbrowa Górnicza




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!

Ten post edytował phpion 7.06.2008, 13:33:20
Go to the top of the page
+Quote Post
nevt
post
Post #7





Grupa: Przyjaciele php.pl
Postów: 1 595
Pomógł: 282
Dołączył: 24.09.2007
Skąd: Reda, Pomorskie.

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


nie ten dział, skoro to poszukiwania gotowca, przenoszę.
Go to the top of the page
+Quote Post

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: 22.08.2025 - 14:54