PHP用pagnation隐藏/显示图像

时间:2016-12-27 07:11:37

标签: php html css arrays multidimensional-array

我希望实现的结果 Something i want to achieve

PS:请忽略中心的错误。

当前 Added pagination

只需更新代码并设法解决 019 问题并循环遍历所有图像一次。但是,仍然无法在一个页面上显示3个图像。

以前设法在css {display}的帮助下显示我想要的内容  和JavaScript显示/隐藏功能,但不知道如何处理PHP。

$productArr = ["ac" => ["001" => ["dimension"=>"H: 85 W: 67 D: 72",  "price"=>850.00 , "images"=>7], 
                    "002" => ["dimension"=>"H: -- W: -- D: --",  "price"=>860.00 , "images"=>7], 
                    "003" => ["dimension"=>"H: 95 W: 71 D: 90",  "price"=>890.00 , "images"=>7], 
                    "004" => ["dimension"=>"H: 78 W: 68 D: 78",  "price"=>740.00 , "images"=>4], 
                    "005" => ["dimension"=>"H: 102 W: 69 D: 90", "price"=>890.00 , "images"=>7], 
                    "006" => ["dimension"=>"H: 89 W: 80 D: 86",  "price"=>1280.00, "images"=>7], 
                    "007" => ["dimension"=>"H: 78 W: 66 D: 66",  "price"=>680.00 , "images"=>7], 
                    "008" => ["dimension"=>"H: 80 W: 78 D: 74",  "price"=>800.00 , "images"=>7], 
                    "009" => ["dimension"=>"H: 94 W: 64 D: 88",  "price"=>790.00 , "images"=>5], 
                    "010" => ["dimension"=>"H: 83 W: 68 D: 72",  "price"=>850.00 , "images"=>7], 
                    "011" => ["dimension"=>"H: 70 W: 66 D: 77",  "price"=>860.00 , "images"=>7], 
                    "012" => ["dimension"=>"H: 88 W: 84 D: 88",  "price"=>1280.00, "images"=>7], 
                    "013" => ["dimension"=>"H: 80 W: 70 D: 84",  "price"=>860.00 , "images"=>7], 
                    "014" => ["dimension"=>"H: 82 W: 68 D: 80",  "price"=>780.00 , "images"=>7], 
                    "015" => ["dimension"=>"H: 82 W: 72 D: 78",  "price"=>890.00 , "images"=>7], 
                    "016" => ["dimension"=>"H: 75 W: 59 D: 47",  "price"=>780.00 , "images"=>7], 
                    "017" => ["dimension"=>"H: 90 W: 77 D: 83",  "price"=>1280.00, "images"=>7], 
                    "018" => ["dimension"=>"H: -- W: -- D: --",  "price"=>680.00 , "images"=>5], 
                    "020" => ["dimension"=>"H: 74 W: 63 D: 89",  "price"=>860.00 , "images"=>4]]

$catCode = $_GET['cat'];

$arr=[];
foreach ($productArr[$catCode] as $imgNumber  => $productDetail) {
    array_push($arr,$imgNumber);
    $imgNumber = $arr;
 // index[18] change to 20
}
       echo"<div align='center'>  
        <ul class='pagination'>";
        for ($i = 1; $i < count($productArr[$catCode]) / 3 + 1; $i++) {
            echo"<li><a href='http://localhost/ca1/collectionPage.php?cat={$catCode}&page={$i}'> {$i}</a></li>
         ";
        }
        echo"<li><a href='http://localhost/ca1/collectionSummary.php?cat={$catCode}'>view all</a></li>";
        echo"</ul>
        </div>";

    for($i=0; $i < count($productArr[$catCode]); $i++){   
        echo  "<div class='col-md-4'>
                <div class='thumbnail'>
                    <img class='img-responsive image_size' src='images/$catCode/row_{$catCode}{$arr[$i]}_m0.jpg'>
                    <div class='caption'>
                        <p align='center'><b>Model No.Row-{$upperCatCode}-{$arr[$i]}</b></p>
                    </div>
                </div>
            </div> ";

}

1 个答案:

答案 0 :(得分:0)

您可以限制索引显示哪些图片,但是您需要将值 FROM TO 发送到php脚本并添加如下的循环:< / p>

if(($i>$FROM)||($i<=$TO))
   {
      // Show the image
   }

如果您将使用已显示的循环。