2016-08-21 2 views
-1

Ich habe Daten wie diese nach Kategorie sortiert:Laravel Klinge - Kopf- und Fußzeile in einer Schleife

Category 1, Product 1, Amount 
Category 1, Product 2, Amount 
Category 2, Product 3, Amount 

Ich mag es drucken mit Klinge als

Category 1 

Product 1 Amount 
Product 2 Amount 
.... 
Total Amount of Category 1 : xxxxx 


Category 2 

Product 3 Amount 
.... 
Total Amount of Category 2 : xxxxx 
+0

I verwendet [@] foreach ($ data als $ row) [@] endforeach Ich weiß, wie Name der neuen Kategorie und Menge, die insgesamt angezeigt werden, das Hauptproblem ist, kann ich nicht Überprüfen Sie, welche Zeile zuletzt in einer bestimmten Kategorie steht. –

+0

Warum hat jemand diese Frage -1? –

Antwort

0

Ich gehe davon aus, dass $ Kategorien das sortierte multidimensionale Array mit Indizes Kategorie, Produkt und Menge.

@for ($i = 0; $i < count($categories) ; $i++) 
     <?php $category_product_toatl=0; ?> 
     {{ $categories[$i]['category'] }} 
     {{ $categories[$i]['product'] }}  {{ $categories[$i]['amount']}} 
     <?php 
       $category_product_total= $category_product_total+ $categories[$i]['amount']; 
     ?> 
     @for ($j = $i+1; $j < count($categories) ; $j++) 
       @if($categories[$i]['category']== $categories[$j]['category']) 
        {{ $categories[$j]['product'] }}  {{ $categories[$j]['amount']}} 
        <?php 
          $category_product_total= $category_product_total+ $categories[$j]['amount']; 
        ?> 
       @else 
        break; 
       @endif 

     @endfor 
    Total Amount of {{ $category[$i] }} : {{ $category_product_total }} 
@endfor 
+0

Danke für Ihre Hilfe. Gibt es eine Möglichkeit zu finden, welche Zeile für jede Kategorie zuletzt ist? –

+0

Ja, wo Sie "Pause" schreiben Anweisung im @else-Teil, der die letzte Zeile für jede Kategorie ist. –