Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][rozwiazane] Podwojne while problem, a moze wystarczy jedno while?
uglukha
post
Post #1





Grupa: Zarejestrowani
Postów: 110
Pomógł: 0
Dołączył: 5.05.2008

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


Witam,
mam taki prosty pewnie problem dla tutejszych wymiataczy. Mam taka petle while do wystwietlania ostatnich komentarzy, dziala ok, ale chcialbym ja ograniczyc do 5 pierwszych petli. Teraz mi wyswietla maksymalna ilosc elementow.

  1. while (list($klucz) = each($czas_pliku))
  2. {
  3. $numerCommenta = $commentPliki[$klucz];
  4. $numerCommenta = str_replace(".php", "", "$numerCommenta");
  5. $numerCommenta = str_replace("komentarze/", "", "$numerCommenta");
  6. settype($numerCommenta, "integer");
  7. $tytulCommenta = $xml->article[$numerCommenta]->title;
  8. echo " ˇ <a href=\"komentarze.php?k=$numerCommenta\">$tytulCommenta</a><br>\n";
  9. }


a tu moje proby zakonczone porazka, wyswteitla sie 5 razy, ale pierwszy element ;(

  1. while (list($klucz) = each($czas_pliku))
  2. $i = 1;
  3. {
  4. while ($i <= 5 )
  5. {
  6.  
  7.  
  8. $i = $i + 1;
  9.  
  10.  
  11. $numerCommenta = $commentPliki[$klucz];
  12. $numerCommenta = str_replace(".php", "", "$numerCommenta");
  13. $numerCommenta = str_replace("komentarze/", "", "$numerCommenta");
  14. settype($numerCommenta, "integer");
  15. $tytulCommenta = $xml->article[$numerCommenta]->title;
  16. echo " ˇ <a href=\"komentarze.php?k=$numerCommenta\">$tytulCommenta</a><br>\n";
  17. }
  18. }


zgory dzieki za pomoc,
pozdrawiam

Ten post edytował uglukha 3.08.2010, 14:22:15
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
Fifi209
post
Post #2





Grupa: Zarejestrowani
Postów: 4 655
Pomógł: 556
Dołączył: 17.03.2009
Skąd: Katowice

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


przed pętlą daj to
  1. $i = 1;


lub użyj static w pętli dla tej zmiennej

Ten post edytował fifi209 3.08.2010, 13:54:24
Go to the top of the page
+Quote Post
uglukha
post
Post #3





Grupa: Zarejestrowani
Postów: 110
Pomógł: 0
Dołączył: 5.05.2008

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


poczytalem manuala o tym static ale nie rozumiem ;(

przesuniecie tego wiersza za duzo nie dalo, ale udalo mi sie wszystko wrzucic do jednego while i dziala:

  1. $i = 1;
  2. while ($i <= 5 )
  3. {
  4. list($klucz) = each($czas_pliku);
  5. $i = $i + 1;
  6. $numerCommenta = $commentPliki[$klucz];
  7. $numerCommenta = str_replace(".php", "", "$numerCommenta");
  8. $numerCommenta = str_replace("komentarze/", "", "$numerCommenta");
  9. settype($numerCommenta, "integer");
  10. $tytulCommenta = $xml->article[$numerCommenta]->title;
  11. echo " ˇ <a href=\"komentarze.php?k=$numerCommenta\">$tytulCommenta</a><br>\n";
  12. }


Ten post edytował uglukha 3.08.2010, 14:21:09
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.12.2025 - 23:45