Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP][rozwiazane] Podwojne while problem
Forum PHP.pl > Forum > Przedszkole
uglukha
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
Fifi209
przed pętlą daj to
  1. $i = 1;


lub użyj static w pętli dla tej zmiennej
uglukha
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. }
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-2025 Invision Power Services, Inc.