Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在foreach循环中使用单独的类反转第二个div集合顺序_Php_Loops_Foreach_Opencart - Fatal编程技术网

Php 在foreach循环中使用单独的类反转第二个div集合顺序

Php 在foreach循环中使用单独的类反转第二个div集合顺序,php,loops,foreach,opencart,Php,Loops,Foreach,Opencart,在foreach循环中使用单独的类反转第二个div集合顺序。 它将是一个架子状的结构。我试图交替使用.tl.tr类 或 我们可以使用css来对齐第二组吗 代码: 我认为这将解决这个问题,它实现了一个计数器来跟踪当前产品应该在左边还是右边 $product_counter = 0; <?php foreach ($products as $product) { ?> <?php $product_counter++; ?> <?php if(!($prod

在foreach循环中使用单独的类反转第二个div集合顺序。 它将是一个架子状的结构。我试图交替使用
.tl
.tr

我们可以使用css来对齐第二组吗

代码:


我认为这将解决这个问题,它实现了一个计数器来跟踪当前产品应该在左边还是右边

$product_counter = 0;
<?php foreach ($products as $product) { ?>
  <?php $product_counter++; ?>

  <?php if(!($product_counter%2 ==0)) { ?>

  <div class="row">
    <div class="shelf">
      <div class="span4">
        // image echo code here
      </div>
      <div class="span2">
        // price, add to cart etc
      </div>

<?php } else { ?>

   <div class="span2">
     // price, add to cart etc
   </div>
   <div class="span4">
     // image echo code here
   </div>

  </div>   <!-- shelf div closing tag -->

  </div>   <!-- row div closing tag -->

  <?php } ?> <!-- closing else -->
  <?php } ?> <!-- closing foreach-->

<!-- in case if there were odd numbers of total product, then close the row and shelf div after foreach -->
<?php if(!($product_counter%2 ==0)) { ?>
 </div>
 </div>
<? } ?>
$product\u计数器=0;
//图像回显代码在这里
//价格、添加到购物车等
//价格、添加到购物车等
//图像回显代码在这里
  .shelf .tl {
    margin-left: 58px;
  }
  .shelf .tr {
    margin-left: -33px;
  }
$product_counter = 0;
<?php foreach ($products as $product) { ?>
  <?php $product_counter++; ?>

  <?php if(!($product_counter%2 ==0)) { ?>

  <div class="row">
    <div class="shelf">
      <div class="span4">
        // image echo code here
      </div>
      <div class="span2">
        // price, add to cart etc
      </div>

<?php } else { ?>

   <div class="span2">
     // price, add to cart etc
   </div>
   <div class="span4">
     // image echo code here
   </div>

  </div>   <!-- shelf div closing tag -->

  </div>   <!-- row div closing tag -->

  <?php } ?> <!-- closing else -->
  <?php } ?> <!-- closing foreach-->

<!-- in case if there were odd numbers of total product, then close the row and shelf div after foreach -->
<?php if(!($product_counter%2 ==0)) { ?>
 </div>
 </div>
<? } ?>