Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Pętla do tworzenia tebeli
Forum PHP.pl > Forum > PHP
R@ven
Mam o to taki kod generujacy mi liste zdjęć:
  1. <?php
  2. $male_dir = './male/';
  3. if ($handle = opendir($male_dir))
  4. {
  5. while (false !== ($file = readdir($handle))) 
  6. {
  7. if ($file != '.' && $file != '..' && $file != 'Thumbs.db') 
  8. {
  9. $image_file = $male_dir.$file;
  10. $image_size = getimagesize($image_file);
  11. echo ('<td><div align="center">');
  12. echo ('<a href="duze/'.$file.'" rel="lightbox">');
  13. echo ('<img src="male/'.$file.'" alt="" '.$image_size[3].' class="img" />');
  14. echo ('</a><br>');
  15. echo ('<a href="duze/'.$file.'" target="_blank">'.$file);
  16. echo ('</a></div></td>');
  17. }
  18. }
  19. }
  20. ?>


Samo tworzenie <td> działa tak jak chcę. Problem w tym że, chce utworzyć tabele po 4 <td>...
I nie mam pojęcia jak zapętlić w/w kod tak aby po 4 wyświetleniu <td> dodawał </tr><tr>.

Chce osciągnąc taki efekt:
  1. <table width="100%" border="0" cellspacing="10" cellpadding="0">
  2. <tr>
  3. <td><div align="center"><a href="duze/IMG_0320.JPG" rel="lightbox"><img src="male/IMG_0320.JPG" alt="" width="200" height="150" class="img" /></a></div></td>
  4. <td><div align="center"><a href="duze/IMG_0321.JPG" rel="lightbox"><img src="male/IMG_0321.JPG" alt="" width="200" height="267" class="img" /></a></div></td>
  5. <td><div align="center"><a href="duze/IMG_0322.JPG" rel="lightbox"><img src="male/IMG_0322.JPG" alt="" width="200" height="150" class="img" /></a></div></td>
  6. <td><div align="center"><a href="duze/IMG_0323.JPG" rel="lightbox"><img src="male/IMG_0323.JPG" alt="" width="200" height="150" class="img" /></a></div></td>
  7. </tr>
  8. <tr>
  9. <td><div align="center"><a href="duze/IMG_0324.JPG" rel="lightbox"><img src="male/IMG_0324.JPG" alt="" width="200" height="150" class="img" /></a></div></td>
  10. <td><div align="center"><a href="duze/IMG_0325.JPG" rel="lightbox"><img src="male/IMG_0325.JPG" alt="" width="200" height="267" class="img" /></a></div></td>
  11. <td><div align="center"><a href="duze/IMG_0326.JPG" rel="lightbox"><img src="male/IMG_0326.JPG" alt="" width="200" height="150" class="img" /></a></div></td>
  12. <td><div align="center"><a href="duze/IMG_0327.JPG" rel="lightbox"><img src="male/IMG_0327.JPG" alt="" width="200" height="150" class="img" /></a></div></td>
  13. </tr>
  14. <tr>
  15. <td><div align="center"><a href="duze/IMG_0328.JPG" rel="lightbox"><img src="male/IMG_0328.JPG" alt="" width="200" height="150" class="img" /></a></div></td>
  16. <td><div align="center"><a href="duze/IMG_0329.JPG" rel="lightbox"><img src="male/IMG_0329.JPG" alt="" width="200" height="150" class="img" /></a></div></td>
  17. <td><div align="center"><a href="duze/IMG_0330.JPG" rel="lightbox"><img src="male/IMG_0330.JPG" alt="" width="200" height="150" class="img" /></a></div></td>
  18. <td><div align="center"><a href="duze/IMG_0331.JPG" rel="lightbox"><img src="male/IMG_0331.JPG" alt="" width="200" height="267" class="img" /></a></div></td>
  19. </tr>
  20. <!-- i tak dalej -->
Ludvik
  1. <?php
  2. $male_dir = './male/';
  3. if ($handle = opendir($male_dir))
  4. {
  5. $licznik = 0;
  6. while (false !== ($file = readdir($handle))) 
  7. {
  8. if ($file != '.' && $file != '..' && $file != 'Thumbs.db') 
  9. {
  10. if (!$licznik) {
  11. // wyswietlasz tr
  12. }
  13. $licznik++;
  14. $image_file = $male_dir.$file;
  15. $image_size = getimagesize($image_file);
  16. echo ('<td><div align="center">');
  17. echo ('<a href="duze/'.$file.'" rel="lightbox">');
  18. echo ('<img src="male/'.$file.'" alt="" '.$image_size[3].' class="img" />');
  19. echo ('</a><br>');
  20. echo ('<a href="duze/'.$file.'" target="_blank">'.$file);
  21. echo ('</a></div></td>');
  22. if ($licznik == 4) {
  23. $licznik = 0;
  24. // zamykasz tr
  25. }
  26. }
  27. }
  28. if ($licznik) {
  29. // wyswietlasz komorke tabeli, dla ktorej colspan = 4 - $licznik
  30. // zamykasz tr
  31. }
  32. }
  33. ?>


Mam nadzieję, że się nie palnąłem.
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.