Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]jak określić ilość elementów w tablicy, mam foreach ($out['V']AS$row) - jak określić ilość e
hajotek
post
Post #1





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 3.06.2010

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


Mam taki fragment kodu:
  1. <?php
  2. $out = $ep3gate->getPlainData('?sp=3&a=2&sd=*1&ed=*22');
  3. print '<table>';
  4. foreach ($out['V'] AS $row)
  5. {
  6. print '<tr><td rowspan="2"><img src="'.$row['hotelimage'].'" width="100px"
  7. height="50px" /></td>';
  8. print '<td valign="top"><strong>'.$row['htlName'].'</strong>';
  9. for ($i=1; $i<=$row['htlCat']; $i++)
  10. print '<img src="images/star1.gif"/>';
  11. print '<br/>'.$row['htlCountry'].' / '.$row['htlRegion'].'</td></tr>';
  12. print '<tr><td>'.$row['htlRoomDesc'].','.$row['htlSrvDesc'].'</td>';
  13. print '<td align="right"><a href="'.$row['URL'].'">od <strong>'.
  14. $row['minprice'].'</strong> PLN</a></td></tr>';
  15. }
  16. print '</table>';
  17. ?>

Chciałbym mieć kontrolę nad tym ile poszczególnych "zestawów elementów się wyświetli". Nie mam pojęcia jak to zrobić, choż mam świadomość, że to pewnie banalne. Bardzo proszę o pomoc.
Pozdrawiam
Powód edycji: [phpion]: bbcode
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Wazniak96
post
Post #2





Grupa: Zarejestrowani
Postów: 550
Pomógł: 75
Dołączył: 5.06.2012
Skąd: Lębork

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


Np. tak, już nie zmieniając pętli.

  1. <?php
  2. $out = $ep3gate->getPlainData('?sp=3&a=2&sd=*1&ed=*22');
  3. print '<table>';
  4. $max = 5; // ilość
  5. $i = 0;
  6. foreach ($out['V'] AS $row)
  7. {
  8. print '<tr><td rowspan="2"><img src="'.$row['hotelimage'].'" width="100px"
  9. height="50px" /></td>';
  10. print '<td valign="top"><strong>'.$row['htlName'].'</strong>';
  11. for ($i=1; $i<=$row['htlCat']; $i++)
  12. print '<img src="images/star1.gif"/>';
  13. print '<br/>'.$row['htlCountry'].' / '.$row['htlRegion'].'</td></tr>';
  14. print '<tr><td>'.$row['htlRoomDesc'].','.$row['htlSrvDesc'].'</td>';
  15. print '<td align="right"><a href="'.$row['URL'].'">od <strong>'.
  16. $row['minprice'].'</strong> PLN</a></td></tr>';
  17.  
  18. $i++;
  19. if($i >= $max)
  20. break;
  21. }
  22. print '</table>';
  23. ?>


Ten post edytował Wazniak96 30.08.2013, 17:35:11
Go to the top of the page
+Quote Post

Posty w temacie


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: 15.10.2025 - 16:53