每隔三次在新行上安排div

时间:2015-12-23 19:21:09

标签: php

我有这个最烦人的问题;我试图在一行上安排三个div,然后是新行,另外三个div等等,如下所示:

 <div class="container">
        <div class="row">
          <div class="col-sm-1">1</div>
          <div class="col-sm-1">2</div>
          <div class="col-sm-1">3</div>
        </div>
        <div class="row">
          <div class="col-sm-1">4</div>
          <div class="col-sm-1">5</div>
          <div class="col-sm-1">6</div>
        </div>
</div>

至于接受answer

  

有一个问题:0%3等于0.这可能导致   如果您的计数器从0开始,则会出现意外结果。

那么我将如何在此代码中实现它:

 <div class="col-md-8">
            <?php
            foreach($this->movies->movie_data as $key => $movie){
                $string = file_get_contents("http://example.com/?t=" . urlencode($movie->movie_titel). "&y=&plot=short&r=json");
                $result = json_decode($string);

        if($result->Response == 'True'){ 
            ?>
            <div class="col-sm-4">
                <?php if($result->Poster == 'N/A') : ?>
                <a href="<?php echo Config::get('URL')?>ladybug/day/<?php echo $this->city ?>/<?php echo $movie->movie_id ?>">
                    <img src="<?php echo Config::get('URL')?>/images/na.png" class="img-responsive img-thumbnail"></a>
                <?php else: ?>
                <a href="<?php echo Config::get('URL')?>ladybug/day/<?php echo $this->city ?>/<?php echo $movie->movie_id ?>">
                    <img src="<?php echo $result->Poster; ?>" class="img-responsive img-thumbnail"></a>
                <?php endif; ?>
                <div><b><?php echo $result->Title; ?></b></div>
                <div><i><?php // echo $result->Plot; ?></i></div>
            </div>

    <?php }else{ ?>

            <div class="col-sm-4">
                <a href="<?php echo Config::get('URL')?>ladybug/day/<?php echo $this->city ?>/<?php echo $movie->movie_id ?>">
                    <img src="<?php echo Config::get('URL')?>/images/na.png" class="img-responsive img-thumbnail"></a>
                <div><b><?php echo $movie->movie_titel ?></b></div>
                <div class="plot"><i><?php //echo 'N/A' ?></i></div>
            </div>       

            <?php }}} ?
            </div>

出于某种原因,divs的排列方式如下: enter image description here

我的问题:如何每隔三次在新行上排列缩略图?

1 个答案:

答案 0 :(得分:0)

Found the answer in the other Q ...没有读过,对不起。

            <?php }
            if (($key + 1) % 3 == 0) { ?>
                </div>
            <?php   }
            }} ?>