Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Pętla do tworzenia tebeli
R@ven
post 1.07.2006, 14:58:04
Post #1





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 20.11.2004

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


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 -->
Go to the top of the page
+Quote Post
Ludvik
post 1.07.2006, 18:53:52
Post #2





Grupa: Przyjaciele php.pl
Postów: 698
Pomógł: 3
Dołączył: 28.03.2004
Skąd: Wrocław

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


  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.

Ten post edytował Ludvik 1.07.2006, 18:54:54


--------------------
Go to the top of the page
+Quote Post

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 Wersja Lo-Fi Aktualny czas: 8.07.2025 - 21:43