2016-11-12 28 views
0

メインタイルの下に字幕を配置しようとしていますが、タイトルを繰り返しています。Yii2のタイトルの下に字幕を配置する方法

<div id="downloads" class="tab-pane" role="tabpanel"> 
    <?php 
    $product_id = $model->id; 
    $downloads_model = Printingmachinedownloads::find()->where(['productid'=>$product_id])->all(); 
    foreach ($downloads_model as $doc) { 
     $doc_type = $doc['type']; 
     $doc_label = $doc['documentlabel']; 
     $doc_title = $doc['documentname']; 
     ?> 
     <div class="amazingcarousel-container-1 tab_style"> 
      <h3><?php echo $doc_type;?></h3> 
      <a target = '_blank' href="<?php echo Yii::$app->homeUrl?>images/printingmachine/downloads/<?php echo $doc_title; ?>"> 
       <?php echo $doc_label ?> 
      </a> 
     </div> 
     <?php 
     } 
     // $doc_title = $downloads_model[0]->documentlabel; 
     ?> 
    </div> 
</div> 

出力は次のようになります。

Current O/P

私は必要なもの

Brochures 
abc 
def 
ghi 


Specificationsheet 
xyz 
lmn 
opq 

で誰もが私が何をすべきかを教えてもらえますか?あなたは少し非を使用することができて、グループで問題が発生した場合

... 
$downloads_model = Printingmachinedownloads::find()->where(['productid'=>$product_id])->groupBy(['type'])->all(); 

foreach($downloads_model as $doc): 
    <div class="amazingcarousel-container-1 tab_style"> 
    <h3><?= type['type'] ?></h3> 
    $subtitles = Printingmachinedownloads::find()->where(['productid'=>$product_id, 'type' => $doc['type'])->all(); 
    foreach($subtitles as $subtitle): 
    <a target = '_blank' href="<?php echo Yii::$app->homeUrl?>images/printingmachine/downloads/<?php echo $subtitle['documentname']; ?>"> 
    <?php echo $subtitle['documentlabel'] ?> 
    </a> 
enforeach; 
</div> 
endforeach; 
... 

:あなたがコンセプトによって新しいMySQLバージョングループの問題を持っていない場合は、事前

答えて

0

おかげで、あなたのようなものを使用することができます

$downloads_model = Printingmachinedownloads::find()->where(['productid'=>$product_id])->orderBy(['type'=>SORT_DESC])->all(); 

$previous_title = ''; $iteration = 1; 
foreach($downloads_model as $doc): 
$subtitles = Printingmachinedownloads::find()->where(['productid'=>$product_id, 'type' => $doc['type'])->all(); 
$count = count($subtitles); 

$previous_title = $previous_title ?: $doc['type']; 

if($previous_title == $doc['type'] && $count == $iteration): 

     <div class="amazingcarousel-container-1 tab_style"> 
     <h3><?= $previous_title ?></h3> 
     foreach($subtitles as $subtitle): 
     <a target = '_blank' href="<?php echo Yii::$app->homeUrl?>images/printingmachine/downloads/<?php echo $subtitle['documentname']; ?>"> 
     <?php echo $subtitle['documentlabel'] ?> 
     </a> 
    enforeach; 
    </div> 

    $previous_title = ''; $iteration = 1; 
else: 
    $iteration++; 
endif; 
endforeach; 

私はそれをテストしませんでしたが、同様の何かがうまくいくはずです。 しかし、私の提案と効果的な方法は、リレーショナルテーブル1のタイトルコンテナを使用して、サブタイトルを含む別の関連テーブルになります。

関連する問題