0
我想隱藏未定義的錯誤偏移,當然,如果能夠最好地解決。PHP錯誤隱藏/解決錯誤未定義偏移
的代碼顯示了我想要的。影像(每頁3個圖像)。 點擊頁面1示出了具有數001,002,003 頁2的圖像顯示出與004005006號等的圖像....
我的代碼
$catCode = isset($_GET["cat"]) ? $_GET["cat"] : "ac"; //getting url
$upperCatCode = strtoupper($catCode);
$arr = [];
//to get my images based on their image number
foreach ($productArr[$catCode] as $imgNumber => $productDetail) {
array_push($arr, $imgNumber);
$imgNumber = $arr;
}
echo"<div align='center'>
<ul class='pagination'>";
// getting the total pages I need for the category if i want to display 3 images per page
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>";
// the loop i used to loop through the images
for ($i = 0; $i < count($productArr[$catCode]); $i++) {
// count the total number of images
$total = count($arr);
// limit the number of images shown
$limit = 3;
//calculate the total number of pages
$totalPages = ceil($total/$limit);
$page = max($page, 1); //get 1 page when $_GET['page'] <= 0
$page = min($page, $totalPages); //get last page when $_GET['page'] > $totalPages
$offset = ($page - 1) * $limit;
if($offset < 0) {$offset = 0;}
$newArr = array_slice($arr, $offset, $limit);
echo "<div class='col-md-4'>
<div class='thumbnail'>
<a href='http://localhost/ca1/collectionDetail.php?cat={$catCode}&itemCode={$newArr[$i]}'><img class='img-responsive image_size' src='images/$catCode/row_{$catCode}{$newArr[$i]}_m0.jpg'></a>
<div class='caption'>
<p align='center'><b>Model No.Row-{$upperCatCode}-{$newArr[$i]}</b></p>
</div>
</div>
</div> ";
該行'145'? – C2486
如果可能,請您可以創建一個小提琴,以便我們可以根據需要進行修改。 –
@Rishi行145:「
」這是循環 –
aaa