Mam pewien kurde problemik. Mam widok w którym sobie wyświetlam ładnie produkty pobrane z DB. Chcę je wyświetlić jeden obok drugiego, trzy produkty w wierszu, wierszy ma być maksylalnie, no niech będzie 3. Wszystko już ładnie oprogramowałem, paginację, itd. Sęk w tym, że wyświetlają mi się podwójnie produkty, nie chcę duplikatów. Kod widoku poniżej, chciałem zastąpić foreach zwyklym for ale coś mi nie wyszło.
Czy mógłbym poprosić o drobną pomoc?
<?php $tmpname = null; ?> <table class="pagination" align="center"> <tr class="pagination"> <td class="pagination"> </td> <td class="pagination"> <div id="pagination"> </div> </td> <td class="products"> </td> </tr> </table> <br /> <table class="products_main" align="center"> <th class="products_main">Nasze produkty</th> <tr><td></td></tr> </table> <table class="products_main"> <tr> <?php $licz = 0; for($i=1;$i<$ile;$i++) { ?> <td valign="top" align="center"> <?php foreach($products as $p): if($tmpname != $p['name']) { ?> <table class="products" > <th id="products_text"> </th><th id="products_text">dane o produkcie</th> <tr class="products" > <td class="products-img"> <?php $filename = $tmpfilename.'_big'.$file_extension; ?> </a> </td> <td class="products-01" id="products_text"> <br /> <b>Opis produktu</b> <br /> <?php //echo $row_count; ?> <br /> <br /> <b>pełny opis</b> </td> </tr> </table> <br /> <?php $tmpname = $p['name']; } endforeach; ?> </td> <?php if(++$licz==3) { $licz = 0; ?> </tr> <tr> <?php } } ?> </tr> </table>
pozdrawiam serdecznie
OKI skoro nikt tu się nie wypowiedział, rozwiązanie poniżej, może komuś się przyda może nie:
<?php $tmpname = null; ?> <table class="pagination" align="center"> <tr class="pagination"> <td class="pagination"> </td> <td class="pagination"> <div id="pagination"> </div> </td> <td class="products"> </td> </tr> </table> <br /> <table class="products_main" align="center"> <th class="products_main" height="5px">Nasze produkty</th> <tr><td></td></tr> </table> <div align="center"> <table class="products_main"> <tr> <?php $licz = 0; ?> <?php foreach($products as $p): if($tmpname != $p['name']) { $licz++; ?> <td valign="top" align="center"> <table class="products" > <th id="products_text"> <?php ?> </th><th id="products_text">informacje ogłoszenia</th> <tr class="products" > <td class="products-img"> <?php // zabawa z nazwą pliku do wyświetlenia w powiększeniu zdjęcia $filename = $tmpfilename.'_big'.$file_extension; ?> </a> </td> <td class="products-01" id="products_text"> <br /> <b>Opis produktu</b> <br /> <?php //echo $row_count; ?> <br /> <br /> <b>pełny opis</b> </td> </tr> </table> <br /> <?php if($licz==2) { $licz = 0; ?> </td> </tr> <tr> <?php } ?> <?php $tmpname = $p['name']; } endforeach; ?> </tr> </table> </div>