dongpankao6133 2016-02-11 17:10
浏览 21
已采纳

Echo自举网格与数组中的图片

I'm probably confusing myself more than is necessary with this.

I have 12 images on my server, and an array that handles their links.

$ppDefault = "images/profile/default/";
$ppDefaultArray = array($pLoc . "p-01.png", $pLoc . "p-02.png", $pLoc . "p-03.png", ...);

My goal is to have this structure:

<div class="row">
    <div class="col-md-3">
        <img class="img-responsive" src="image.png" />
    </div>
    <div class="col-md-3">
        <img class="img-responsive" src="image.png" />
    </div>
    <div class="col-md-3">
        <img class="img-responsive" src="image.png" />
    </div>
    <div class="col-md-3">
        <img class="img-responsive" src="image.png" />
    </div>
</div>
And so on with more rows and columns

Currently my php code is as follows:

<?php
    $count = 4;
    for ($i = 0; $i < count($ppDefaultArray); $i++) {
        if ($count % 4 == 0) {
            echo 
                '<div class="row">';
                for ($j = 0; $j < 4; $j++) {
                    echo '<div class="col-md-3"><img class="img-responsive" src="' . $ppDefaultArray[$i] . '"/></div>';
                }
                echo '</div>';
        } else {
            for ($j = 0; $j < 4; $j++) {
                echo '<div class="col-md-3"><img class="img-responsive" src="' . $ppDefaultArray[$i] . '"/></div>';
            }
        }
        $count++;
    }   
?>

Which outputs me something like this: enter image description here

Which is not what I need. I need each picture to only show up once and I'm assuming some tags are missing as some pictures are misaligned.

If desired I can post the resulting HTML created but it is quite large.

  • 写回答

4条回答 默认 最新

  • dousi8559 2016-02-11 17:26
    关注

    Try this

    <?php
    
    echo '<div class="row">';
    for ($i = 0; $i < count($ppDefaultArray); $i++) {
        echo '<div class="col-md-3"><img class="img-responsive" src="' . $ppDefaultArray[$i] . '"/></div>';
        if (($i+1) % 4 == 0)
            echo '</div><div class="row">';
    }   
    echo '</div>';
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?