Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [SMARTY] Problem z foreach
Forum PHP.pl > Forum > Gotowe rozwiązania > Systemy szablonów
gutek84
To jest moj plik.tpl

Kod
{$today}
{include file="header_ivt.tpl"}
<table align="center" width="70%">
<tr>
<td colspan="16" class="tab_uberschrift_1" align="center">Info About current rents</td>
</tr>
<tr>
<th colspan="2" class="tab_uberschrift_1">Num</th>
<th colspan="2" class="tab_uberschrift_1">Category</th>
<th colspan="2" class="tab_uberschrift_1">Name</th>
<th colspan="2" class="tab_uberschrift_1">RentDate</th>
<th colspan="2" class="tab_uberschrift_1">Owner</th>
<th colspan="2" class="tab_uberschrift_1">RentPerson</th>
<th colspan="2" class="tab_uberschrift_1">RentForPerson</th>
<th colspan="2" class="tab_uberschrift_1">GetBackDate</th>
</tr>
{foreach name=rent item=rent from=$rent}
{if $today gt $rent.getbackdate}
<tr> <td class="tab_uberschrift_2" colspan="2" align="center">{$smarty.foreach.rent.iteration}</td>
    {foreach name=ren1 from=$rent item=rent}
            <td class="tab_uberschrift_2" colspan="2" align="center">{$rent}</td>
    {/foreach}
<td class="tab_uberschrift_2" align="center"><a href="cal.html"><img src="gfx/datechooser.png" alt="EDIT DATE" ></a></td>
</tr>
{else}
<tr> <td class="tab_uberschrift_3" colspan="2" align="center">{$smarty.foreach.rent.iteration}</td>
    {foreach name=ren2 from=$rent item=rent}
            <td class="tab_uberschrift_3" colspan="2" align="center">{$rent}</td>
    {/foreach}
<td class="tab_uberschrift_3" align="center"><a href="cal.html"><img src="gfx/datechooser.png" alt="EDIT DATE" ></a></td>
</tr>
{/if}
{/foreach}
</table>


Problem polega na tym ze jak chce wyswietic tabele w zaleznosci od warunku if (wiersz tabeli ma miec kolor1 lub kolor2 z css'a). Zmienna $rent jest tablica. Mam wrazenie jakby brany byl tylko pierwszy element 
tablicy choc jest w petli. Gdy zmienie warunek z gt- (>) na lt- (<) to wtedy wszystkie wiersze zaznaczone sa na kolor 2. Podejrzewam ze mam blad w petli, albo w warunku.
Prosze o pomoc
Jojo
  1. {foreach name=rent item=rent from=$rent}

Bierzesz element z tablicy $rent i wpisujesz go do zmiennej o nazwie $rent... ciekawe czemu drugi obrót pętli się nie wykonuje?

Zrób tak:
  1. {foreach name=rent item=rent_item from=$rent}
A wewnątrz pętli odwołuj się przez $rent_item.
gutek84
Z tego co zrozumialem to zrobilem tak:

Kod
{foreach name=rent item=rent_item from=$rent}

{if $smarty.now|date_format:"%Y-%m-%d" gt $rent.getbackdate}

<tr> <td class="tab_uberschrift_2" colspan="2" align="center">{$smarty.foreach.rent.iteration}</td>

    {foreach name=ren1 from=$rent_item item=rent}
                <td class="tab_uberschrift_2" colspan="2" align="center">{$rent}</td>
                {/foreach}<form name="date" action="data.php" method="POST">
    <td class="tab_uberschrift_2" align="center"><a onclick="showKal(this)"><img src="gfx/datechooser.png" alt="EDIT DATE"></a></td></form>

</tr>

{else}

<tr> <td class="tab_uberschrift_3" colspan="2" align="center">{$smarty.foreach.rent.iteration}</td>

    {foreach name=ren1 from=$rent_item item=rent}

            <td class="tab_uberschrift_3" colspan="2" align="center">{$rent}</td>

    {/foreach}<form name="date" action="date.php" method="POST">

<td class="tab_uberschrift_3" align="center"><a onclick="showKal(this)"><img src="gfx/datechooser.png" alt="EDIT DATE"></a></td></form>

</tr>

{/if}

{/foreach}


Ale pomimo to wyswietla mi sie dalej to samo, tzn. nie podswietla elementow spelniajacych warunek
Cezar708
jojo napisał:

  1. {foreach name=rent item=rent_item from=$rent}

a Ty napisałeś:
  1. {foreach name=ren1 from=$rent_item item=rent}


widzisz różnicę?
gutek84
Kod
jojo napisał:

HTML
{foreach name=rent item=rent_item from=$rent}

a Ty napisałeś:
HTML
{foreach name=ren1 from=$rent_item item=rent}


widzisz różnicę?


Pierwszy foreach to petla zewnetrzna, a drugi to wewnetrzna do ktorej sie chce odwolac. Jesli wpisalbym w petle to co mi podales to petle nie zadzialaja. Nie wiem przypadkiem czy blad dzialania petli nie jest spowodowany warunkiem. Sprawdzalem rozne kombinacje (gt,ge,lt,le,eq) i za kazdym razem dane wyswietla nieprawidlowo, tzn. nie podkresla mi odpowiednich rekordow.
pozdr

Na pewno blad spowodowany warunkiem!!!

I teraz pytanie :
Kod
{if $smarty.now|date_format:"%Y-%m-%d" gt $rent.getbackdate}
, tu mam instrukcje warunkowa if. dalej jest porownanie i blad wystepuje w wyswietleniu przez $rent_item.r_getbackdate, otoz powinna to byc data a jak chce wyswietlic sama date to wywala mi tylko pierwsza cyfre. Np. jak mam rok 2007 to do porównania jest brana tylko 2!! Jak zrobic zeby bral cala date?
naroonline
Dokładnie tak
{foreach name=ren1 from=$rent_item item=rent}
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.