Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

2 Stron V   1 2 >  
Reply to this topicStart new topic
> [PHP]wyswietlenie harmonogramu dat
shaolin33
post
Post #1





Grupa: Zarejestrowani
Postów: 136
Pomógł: 0
Dołączył: 5.10.2012

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


witam,

potrzebuje pomocy w utworzeniu harmonogramu dat


mam datę w formacie:

2013-08-31

oraz
okres= 10 miesięcy


chce wyświetlić w tabeli kolejno 10 miesiący od daty 2013-08-31



1 2013-08-31
2 2013-09-30
3 2013-10-31
4 2013-11-30
5 2013-12-31
6 2014-01-31
7 2014-02-28
8 2014-03-31
9 2014-04-30
10 2014-05-31
Go to the top of the page
+Quote Post
freemp3
post
Post #2





Grupa: Zarejestrowani
Postów: 467
Pomógł: 77
Dołączył: 6.09.2008
Skąd: Miechów / Kraków

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


Możesz użyć klas DateTime oraz DateInterval:

http://www.php.net/manual/pl/class.datetime.php
http://php.net/manual/pl/class.dateinterval.php


--------------------
Niemożliwym jest stworzenie czegokolwiek idiotoodpornego, ponieważ idioci są wyjątkowo pomysłowi.

https://www.aroch.pl
https://themeforest.net/user/aroch
https://www.astroblog.aroch.pl
https://www.4geeks.pl
Go to the top of the page
+Quote Post
pianta_d
post
Post #3





Grupa: Zarejestrowani
Postów: 176
Pomógł: 18
Dołączył: 5.01.2007

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


http://forum.webhelp.pl/php-i-bazy-danych/...ni-t137935.html

Na dole masz sekcję Podobne linki, gdzie jest mnóstwo informacji na ten temat

Pozdrawiam
Go to the top of the page
+Quote Post
rocktech.pl
post
Post #4





Grupa: Zarejestrowani
Postów: 587
Pomógł: 131
Dołączył: 8.02.2010

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


Witam.

  1. $begin = new DateTime('2013-08-01');
  2. $end = clone($begin);
  3. $end->modify("+1 year");
  4. /**
  5.  * @see <http://en.wikipedia.org/wiki/ISO_8601#Time_intervals>
  6.  */
  7. $interval = new DateInterval('P1M');
  8. $daterange = new DatePeriod($begin, $interval, $end);
  9.  
  10. foreach ( $daterange as $date ) {
  11. echo $date->format("Y-m-d").PHP_EOL;
  12. }


Jeżeli masz jakieś pytania odnośnie powyższego kodu to strzelaj. Temat nie jest do końca oczywisty ...

Ten post edytował rocktech.pl 26.08.2013, 08:27:08


--------------------
Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. --Brian Moore

I never go looking for a sucker. I look for a Champion and make a sucker of of him. --Amarillo Slim


Home-made : js-gui-classes | Accordion | Tabs | Carousel / php-sms-classes | Obsługa bramki SMS MultiInfo | Obsługa bramki SMS Mobiltek
Go to the top of the page
+Quote Post
shaolin33
post
Post #5





Grupa: Zarejestrowani
Postów: 136
Pomógł: 0
Dołączył: 5.10.2012

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


Cytat(rocktech.pl @ 26.08.2013, 09:25:51 ) *
Witam.

  1. $begin = new DateTime('2013-08-01');
  2. $end = clone($begin);
  3. $end->modify("+1 year");
  4. /**
  5.  * @see <http://en.wikipedia.org/wiki/ISO_8601#Time_intervals>
  6.  */
  7. $interval = new DateInterval('P1M');
  8. $daterange = new DatePeriod($begin, $interval, $end);
  9.  
  10. foreach ( $daterange as $date ) {
  11. echo $date->format("Y-m-d").PHP_EOL;
  12. }


Jeżeli masz jakieś pytania odnośnie powyższego kodu to strzelaj. Temat nie jest do końca oczywisty ...




top jest dla mnie neijasne: $interval = new DateInterval('P1M');

jak zmieniam w tym miejscu date $begin = new DateTime('2013-08-01'); na 2013-08-31 to nie pokazuje mi kolejnych ostattnich dni miesiąca
Go to the top of the page
+Quote Post
rocktech.pl
post
Post #6





Grupa: Zarejestrowani
Postów: 587
Pomógł: 131
Dołączył: 8.02.2010

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


Zmień na:

  1. //Period30Days
  2. $interval = new DateInterval('P30D');


Przejrzyj link z wiki.


--------------------
Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. --Brian Moore

I never go looking for a sucker. I look for a Champion and make a sucker of of him. --Amarillo Slim


Home-made : js-gui-classes | Accordion | Tabs | Carousel / php-sms-classes | Obsługa bramki SMS MultiInfo | Obsługa bramki SMS Mobiltek
Go to the top of the page
+Quote Post
shaolin33
post
Post #7





Grupa: Zarejestrowani
Postów: 136
Pomógł: 0
Dołączył: 5.10.2012

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


Cytat(rocktech.pl @ 26.08.2013, 09:46:36 ) *
Zmień na:

  1. //Period30Days
  2. $interval = new DateInterval('P30D');


Przejrzyj link z wiki.



no spoko tylko że wyswietla niezbyt poprawnie:


2013-08-31
2013-09-30
2013-10-30
2013-11-29
2013-12-29
2014-01-28
2014-02-27
2014-03-29
2014-04-28
2014-05-28
2014-06-27
2014-07-27
2014-08-26

i jeszcze jeden aspekt

okres jest zmienny wiec czasem to bedzie 12 miesiecy a czasem 65 miesiecy

czyli w takim przypadku musze ta linijke:

$end->modify("+1 year");

zmodyfikowac pod zmienna $okres ?
Go to the top of the page
+Quote Post
rocktech.pl
post
Post #8





Grupa: Zarejestrowani
Postów: 587
Pomógł: 131
Dołączył: 8.02.2010

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


Dokładnie obiektowo.

  1. $end->modify("+65 months");


Co do ostatniego dnia możesz użyć formatu t - liczba dni w miesiącu.

  1. foreach ( $daterange as $date ) {
  2. echo $date->format("Y-m-t").PHP_EOL;
  3. }


--------------------
Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. --Brian Moore

I never go looking for a sucker. I look for a Champion and make a sucker of of him. --Amarillo Slim


Home-made : js-gui-classes | Accordion | Tabs | Carousel / php-sms-classes | Obsługa bramki SMS MultiInfo | Obsługa bramki SMS Mobiltek
Go to the top of the page
+Quote Post
shaolin33
post
Post #9





Grupa: Zarejestrowani
Postów: 136
Pomógł: 0
Dołączył: 5.10.2012

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


$dane[152] - tutaj przyjmuje różne wartości

po wstawieniu nie wyswietla mi dat:(


$begin = new DateTime('2013-08-31');
$end = clone($begin);
$end->modify("+$dane[152]months");
Go to the top of the page
+Quote Post
nospor
post
Post #10





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




miedzy wartoscia ile a tekstem month ma byc spacja... naprawde nie widzisz jej w kodzie poprzednika?
Powód edycji: [nospor]:


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
shaolin33
post
Post #11





Grupa: Zarejestrowani
Postów: 136
Pomógł: 0
Dołączył: 5.10.2012

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


Cytat(nospor @ 26.08.2013, 11:02:15 ) *
miedzy wartoscia ile a tekstem month ma byc spacja... naprawde nie widzisz jej w kodzie poprzednika?


teraz widze ale nadal nie śmiga smile.gif

$dane[152]
pobieram z sqla
Go to the top of the page
+Quote Post
pianta_d
post
Post #12





Grupa: Zarejestrowani
Postów: 176
Pomógł: 18
Dołączył: 5.01.2007

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


$end->modify("+65 months"); zmień na $end->modify("+152 months");

Sorki, nie doczytałem, że pobierasz z sql smile.gif

$dane=ile_miesięcy;
$end->modify("+".$dane." year");

Nei mogę tego sprawdzić bo mi serwer padł

Ten post edytował pianta_d 26.08.2013, 10:21:02
Go to the top of the page
+Quote Post
shaolin33
post
Post #13





Grupa: Zarejestrowani
Postów: 136
Pomógł: 0
Dołączył: 5.10.2012

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


Cytat(pianta_d @ 26.08.2013, 11:10:25 ) *
$end->modify("+65 months"); zmień na $end->modify("+152 months");

Sorki, nie doczytałem, że pobierasz z sql smile.gif

$dane=ile_miesięcy;
$end->modify("+".$dane." year");

Nei mogę tego sprawdzić bo mi serwer padł






  1. $begin = new DateTime('2013-08-31');
  2. $end = clone($begin);
  3. $end->modify("+".$dane[152]."month");
  4. /**
  5.   * @see <http://en.wikipedia.org/wiki/ISO_8601#Time_intervals>
  6.   */
  7. $interval = new DateInterval('P30D');
  8. $daterange = new DatePeriod($begin, $interval, $end);
  9.  
  10. foreach ( $daterange as $date ) {
  11. echo $date->format("Y-m-t").PHP_EOL;
  12. }



nie wyświetla smile.gif
Go to the top of the page
+Quote Post
rocktech.pl
post
Post #14





Grupa: Zarejestrowani
Postów: 587
Pomógł: 131
Dołączył: 8.02.2010

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


Hej.

  1. $end->modify("+".$dane[152]." months");


A jak nie działa to:

  1. echo "+".$dane[152]." months";


--------------------
Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. --Brian Moore

I never go looking for a sucker. I look for a Champion and make a sucker of of him. --Amarillo Slim


Home-made : js-gui-classes | Accordion | Tabs | Carousel / php-sms-classes | Obsługa bramki SMS MultiInfo | Obsługa bramki SMS Mobiltek
Go to the top of the page
+Quote Post
shaolin33
post
Post #15





Grupa: Zarejestrowani
Postów: 136
Pomógł: 0
Dołączył: 5.10.2012

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


dziękuje, teraz smiga smile.gif

chciałbym jeszcze do wrzucić w tabelkę jedno pod drugim (czyli w jednej z kolumn) ale jak dodaje sama zmienna to mi nie smiga smile.gif
:



  1. echo '<table border="1">' ;
  2.  
  3.  
  4. echo '<tr><td><font size="2">LP.</font></td> <td><font size="2">DATA</font></td><td><font size="2">3 KOLUMNA</font></td><<td><font size="2">4 KOLUMNA</font></td><td><font size="2">5 KOLUMNA</font></td></tr>';
  5.  
  6.  
  7.  
  8.  
  9. echo '<tr> <td>$wiersz[0]</td><td>'.$date.'</td> <td>$wiersz[2]</td><td>$wiersz[3]</td><td>$wiersz[4]</td> </tr>';
  10.  
  11.  
  12. echo '</table>' ;
  13.  


SELECTEM chyba tego nie zrobie? bo t onie idzie z sqla ?

prawda?

Ten post edytował shaolin33 26.08.2013, 11:32:50
Go to the top of the page
+Quote Post
Turson
post
Post #16





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Wrzuć w pętle
Go to the top of the page
+Quote Post
shaolin33
post
Post #17





Grupa: Zarejestrowani
Postów: 136
Pomógł: 0
Dołączył: 5.10.2012

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


Cytat(TursoN @ 26.08.2013, 13:28:00 ) *
Wrzuć w pętle



mozna prosić o przykład ?

  1. $begin = new DateTime('2013-08-31');
  2. $end = clone($begin);
  3. $end->modify("+".$dane[158]." months");
  4. $interval = new DateInterval('P30D');
  5. $daterange = new DatePeriod($begin, $interval, $end);
  6.  
  7. foreach ( $daterange as $date ) {
  8. echo $date->format("Y-m-t").PHP_EOL;
  9. }
  10.  
  11. //DO TEGO MOMENTU JEST OK, PONIŻEJ JUŻ MI NIE POKAZUJE TEBALEKI I DANYCH W KOLUMNIE
  12.  
  13.  
  14.  
  15. $wiersze = explode(',', $date);
  16. echo '<table>';
  17. foreach($wiersze as $wiersz) {
  18. $kolumny = explode('-', $wiersz);
  19. echo '<tr>';
  20. foreach($kolumny as $kolumna) {
  21. echo '<td>'.$kolumna.'</td>';
  22. }
  23. echo '</tr>';
  24. }
  25. echo '</table>';


no tu juz nie mam pomyslu jak to ogarnac zeby poprawie to wyswietlalo:(

Go to the top of the page
+Quote Post
Turson
post
Post #18





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Explode wywala dane w tablicy, np. $kolumny[0] $kolumny[1] itd, czyli zastosuj for()


PS wartośc w [] musi rosnąć automatycznie

Ten post edytował TursoN 29.08.2013, 12:19:10
Go to the top of the page
+Quote Post
shaolin33
post
Post #19





Grupa: Zarejestrowani
Postów: 136
Pomógł: 0
Dołączył: 5.10.2012

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


  1. $begin = new DateTime('2013-08-31');
  2. $end = clone($begin);
  3. $end->modify("+".$dane[158]." months");
  4. $interval = new DateInterval('P30D');
  5. $daterange = new DatePeriod($begin, $interval, $end);
  6.  
  7. foreach ( $daterange as $date ) {
  8. echo $date->format("Y-m-t").PHP_EOL;
  9. }
  10.  
  11. $wiersze = for(',', $date);
  12. echo '<table>';
  13. foreach($wiersze as $wiersz) {
  14. $kolumny = for('-', $wiersz);
  15. echo '<tr>';
  16. foreach($kolumny as $kolumna) {
  17. echo '<td>'.$kolumna.'</td>';
  18. }
  19. echo '</tr>';
  20. }
  21. echo '</table>';


poprawnie to napisalem czy cos pominalem ? bo bez zmian smile.gif
Go to the top of the page
+Quote Post
rocktech.pl
post
Post #20





Grupa: Zarejestrowani
Postów: 587
Pomógł: 131
Dołączył: 8.02.2010

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


Żeby było jasne co chcesz osiągnąć wklej HTML w takiej postaci:

  1. <tr>
  2. <th>Co</td>
  3. <th>Co</td>
  4. </tr>
  5. </thead>
  6. <tr>
  7. <td>Wartość [np. 2012]</td>
  8. <td>Wartość [np. 1]</td>
  9. </tr>
  10. </tbody>


--------------------
Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. --Brian Moore

I never go looking for a sucker. I look for a Champion and make a sucker of of him. --Amarillo Slim


Home-made : js-gui-classes | Accordion | Tabs | Carousel / php-sms-classes | Obsługa bramki SMS MultiInfo | Obsługa bramki SMS Mobiltek
Go to the top of the page
+Quote Post

2 Stron V   1 2 >
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 Aktualny czas: 22.08.2025 - 05:27