0

私が欲しいものは、説明するのが少し難しいです。混乱をお詫び申し上げます。製品用に作成した属性のグループ (合計 16 個) を取得しています。そして、この 16 の属性は、タイプに基づいて 4 つの列 (A、B、C、D) に分けることができます。そこで、A、B、C、D を見出しとして表を作成したいと思います。次に、関連する列のラベルとデータを表示したいと思います。以下は、私が欲しいもののアイデアを提供します。

<table>
<tr>
<td>heading-A</td>
<td>heading-B</td>
<td>heading-C</td>
<td>heading-D</td>
</tr>
<tr>
<td>label-A</td>
<td>Data-A</td>
<td>label-B</td>
<td>Data-B</td>
<td>label-C</td>
<td>Data-C</td>
<td>Label-D</td>
<td>Data-D</td>
</tr>
<tr>...and so on
</table

*見出し-Aの下にラベル-Aとデータ-Aを入れても問題ありません。CSSを使用してそれを実現できます。

関連する各テーブルで属性名を直接呼び出す (つまり、$_product->getAttribute) ことで、これを実行できることがわかっています。しかし問題は、いくつかの属性セットがあり、それぞれが異なる属性を持っていることです (つまり、16 の属性グループがセットごとに異なります)。

そのため、巨大なテーブルを作成して値を個別に呼び出す代わりに、疑似コードを使用してこれを実現しようとしています。これは、それを行うためのはるかにシンプルでスマートな方法です。

これまでのところ、私は次のように試しました:

$attributes = $_product->getAttributes();
<table>
<tr>
<td>Sight</td>
<td>Nose</td>
<td>Palate</td>
<td>Finish</td>
</tr>
<?php foreach($attributes as $attribute):?>
                    <?php if($attribute->getIsVisibleOnFront() && $attribute->getIsUserDefined()):?>
                        <tr>
                            <?php if(stripos($attribute->getAttributeCode(), "_sight")!=0):?><td><th class="data"><?php echo $attribute->getFrontend()->getLabel(); ?></th></td>
                            <td class="data"><?php echo $attribute->getFrontend()->getValue($_product); continue;?></td><?php endif; ?>

                            <?php if(stripos($attribute->getAttributeCode(), "_nose")!=0): ?><td><th class="data"><?php echo $attribute->getFrontend()->getLabel(); ?></th></td>
                            <td class="data"><?php echo $attribute->getFrontend()->getValue($_product); continue;?></td><?php endif; ?>

                            <?php if(stripos($attribute->getAttributeCode(), "_palate")!=0): ?><td><th class="data"><?php echo $attribute->getFrontend()->getLabel(); ?></th></td>
                            <td class="data"><?php echo $attribute->getFrontend()->getValue($_product); continue;?></td><?php endif;?>

                            <?php if(stripos($attribute->getAttributeCode(), "_finish")!=0): ?><td><th class="data"><?php echo $attribute->getFrontend()->getLabel(); ?></th></td>
                            <td class="data"><?php echo $attribute->getFrontend()->getValue($_product); continue;?></td><?php endif;?>
                        </tr>
                    <?php endif; ?>
                <?php endforeach; ?>
</table>

しかし、これはすべて単一の列に出力を与えています。それらを希望どおりに4列に分割する方法がわかりません。誰かがこれについて私を助けることができますか?

4

1 に答える 1

1

続行すると、ループが停止し、次の反復に進みます。

4列の見出しと8列のデータがあります。

<th>は見出しセル用ですhttp://www.w3schools.com/tags/tag_th.asp

ですから、次のことがあなたの解決策にもっと役立つことを願っています。

$attributes = $_product->getAttributes();
<table>
<tr>
<td colspan="2">Sight</td>
<td colspan="2">Nose</td>
<td colspan="2">Palate</td>
<td colspan="2">Finish</td>
</tr>

<?php foreach($attributes as $attribute):
  if($attribute->getIsVisibleOnFront() && $attribute->getIsUserDefined()):?>
      <tr>
          <?php if(stripos($attribute->getAttributeCode(), "_sight")!=0) { ?>
              <td class="label"><?php echo $attribute->getFrontend()->getLabel();          ?></td>
              <td class="data"><?php  echo $attribute->getFrontend()->getValue($_product); ?></td>
          <?php } else { ?>
              <td class="label"></td>
              <td class="data"></td>
          <?php } ?>

          <?php if(stripos($attribute->getAttributeCode(), "_nose")!=0) { ?>
              <td class="label"><?php echo $attribute->getFrontend()->getLabel();          ?></td>
              <td class="data"><?php  echo $attribute->getFrontend()->getValue($_product); ?></td>
          <?php } else { ?>
              <td class="label"></td>
              <td class="data"></td>
          <?php } ?>

          <?php if(stripos($attribute->getAttributeCode(), "_palate")!=0) { ?>
              <td class="label"><?php echo $attribute->getFrontend()->getLabel();          ?></td>
              <td class="data"><?php  echo $attribute->getFrontend()->getValue($_product); ?></td>
          <?php } else { ?>
              <td class="label"></td>
              <td class="data"></td>
          <?php } ?>

          <?php if(stripos($attribute->getAttributeCode(), "_finish")!=0) { ?>
              <td class="label"><?php echo $attribute->getFrontend()->getLabel();         ?></td>
              <td class="data"><?php  echo $attribute->getFrontend()->getValue($_product);?></td>
          <?php } else { ?>
              <td class="label"></td>
              <td class="data"></td>
          <?php } ?>
      </tr>
  <?php endif; ?>
<?php endforeach; ?>
</table>
于 2012-10-10T13:29:31.470 に答える