[Funktion] Mathematische Funktion, wer kann mir helfen ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Funktion] Mathematische Funktion, wer kann mir helfen ?

    Hallo Leute,

    ich bastle gerade an einem OpenSource Dating System.
    Ich habe eine hompage.tpl, in dem definiert ist, wie die neuen Userprofile angezeigt werden sollen.

    Mit der aktuellen Einstellung werden pro Zeile 2 neue Profile angezeigt.
    Ich möchte dies aber ändern, da z.B. 5 neue Userprofile pro Zeile angezeigt wird und dann erst eine neue Zeile angefangen wird.

    Was muss hier ändern um das zu erreichen?


    PHP Code:
                            <table  width="571" cellpadding="0" cellspacing="10" border="0">
                            {
    assign var="ccount" value="0"}
                            {foreach 
    item=item key=key from=$users}
                                {if 
    $ccount==0}
                                    <
    tr>
                                {/if}
                                    <
    td>{include file="userresultviewsmall.tpl"}</td>
                                {if 
    $ccount==1}
                                    </
    tr>
                                {/if}
                                {
    math equation="$ccount+1" assign="ccount"}
                                {
    math equation="$ccount%2" assign="ccount"}
                            {/foreach}
                            </
    table

    Danke
    Last edited by TrippleEx; 16-06-2006, 17:39.

  • #2
    Lass dir $ccount einfach mit ausgeben und schau, wann du wie auf welchen Wert reagieren willst.

    So könnts zum Beispiel schon hinkommen ...
    PHP Code:
    {assign var="ccount" value="0"}
    {foreach 
    item=item key=key from=$users}
        {if 
    $ccount==0}<tr>{/if}
        <!-- ... -->
        {if 
    $ccount==4}</tr>{/if}
        {
    math equation="$ccount+1" assign="ccount"}
        {
    math equation="$ccount%5" assign="ccount"}
    {/foreach} 
    Aber du kannst es dir auch leichter machen:
    PHP Code:
    {assign var="ccount" value="0"}
    {foreach 
    item=item key=key from=$users}
        {if 
    $ccount==0}<tr>{/if}
        <!-- ... -->
        {
    math equation="$ccount+1" assign="ccount"}
        {if 
    $ccount==5}</tr>{math equation="0" assign="ccount"}{/if}
    {/foreach} 
    Last edited by onemorenerd; 16-06-2006, 17:49.

    Comment


    • #3
      Vielen Dank onemorenerd,

      es hat funktioniert. rocks:

      Darf ich dich auch fragen, was hierbei passiert ? Ich möchte das auch verstehen.

      Comment


      • #4
        PHP Code:
        ccount wird auf 0 gesetzt
        {assign var="ccount" value="0"
        {foreach 
        item=item key=key from=$users}
            
        wenn ccount=0 istein tr ausgeben
            
        {if $ccount==0}<tr>{/if}
            <!-- ... -->
            
        wenn ccount=4 istein /tr ausgeben
            
        {if $ccount==4}</tr>{/if}
            
        ccount wird um 1 erhöht
            
        {math equation="$ccount+1" assign="ccount"}
            
        ccount wird mit dem Rest der Division ccount:5 belegt
            
        {math equation="$ccount%5" assign="ccount"}
        {/foreach} 
        PHP Code:
        ccount wird auf 0 gesetzt
        {assign var="ccount" value="0"}
        {foreach 
        item=item key=key from=$users}
            
        wenn ccount=0 istein tr ausgeben
            
        {if $ccount==0}<tr>{/if}
            <!-- ... -->
            
        ccount wird um 1 erhöht
            
        {math equation="$ccount+1" assign="ccount"}
            
        wenn ccount=4 istein /tr ausgeben und ccount wieder auf 0 gesetzt
            
        {if $ccount==5}</tr>{math equation="0" assign="ccount"}{/if}
        {/foreach} 
        Spiele es mal gedanklich durch, dann wirds klar.
        http://smarty.php.net erklärt die einzelnen Anweisung en detail.

        Comment


        • #5
          Big Thanks, ich werde mir mal smarty reinziehen, hast mir echt weitergeholfen.

          Comment

          Working...
          X