Table of Contents
谁帮忙看看 这个代码为什么不会循环
Jun 23, 2016 pm 02:38 PM
<?phpfor($i=0;$i<3;$i++){?><div class="dptj1_coloum xxx<?php echo $i ?>"><?php$items = array(); $widths=273; $heights=273; $szzkj = explode(",",$_MODULE["szzkj"]);switch($_MODULE[huoqubaobei]){ case "1": $items = $itemManager->queryByKeyword($_MODULE[guanjianzi],$_MODULE[paixu],$_MODULE[geshu]); break; case "2": $arr = explode(',',$_MODULE[item_1]); foreach($arr as $value){ $item=$itemManager-> queryById ($value); array_push($items, $item); } break; case "3": $arr = explode(',',$_MODULE[cate_1]); $items = $itemManager->queryByCategory($categoryId,$_MODULE["paixu"],$_MODULE["geshu"]); break; case "4": $srtpdz = explode(",",$_MODULE["srtpdz"]); $srtpljdz = explode(",",$_MODULE["srtpljdz"]); $srbbbt = explode(",",$_MODULE["srbbbt"]); $srbbjg = explode(",",$_MODULE["srbbjg"]); $srxssl = explode(",",$_MODULE["srxssl"]); break;}if($_MODULE[huoqubaobei]!="4"){ $i=-1; foreach($items as $item){ $i++; $itemUrl = $uriManager->detailURI($item); $itemPicUrl = $item->getPicUrl(310); $itemTitle = $item->title; $itemPrice = $item->price; $itemsoldCount = $item->soldCount; echo'<div class="dptj1_coloum1"><div class="dptj1_coloum1_dri"><div class="jiantou"><img src="/static/imghw/default1.png" data-src="assets/images/youjiantou.png" class="lazy" / alt="谁帮忙看看 这个代码为什么不会循环" ></div><div class="content"><div class="wz"><a target="_blank" href="'.$itemUrl.'">'.$itemTitle.'</a></div><div class="price"><span class="price1">RMB:'.$itemPrice.'</span><span class="price2">¥ '.$szzkj[$i].'</span></div><div class="yishou">已售'.$itemsoldCount.'件</div></div></div><div class="dptj1_coloum1_pic"><a target="_blank" href="#"><img src="/static/imghw/default1.png" data-src="'.$itemPicUrl.'" class="lazy" style="max-width:90%" .$itemPicUrl.'" / alt="谁帮忙看看 这个代码为什么不会循环" ></a></div></div>'; }}else if($_MODULE[huoqubaobei]=="4"){ $num = count($srtpdz); for($i=0;$i<$num;$i++) { echo'<div class="dptj1_coloum1"><div class="dptj1_coloum1_dri"><div class="jiantou"><img src="/static/imghw/default1.png" data-src="assets/images/youjiantou.png" class="lazy" / alt="谁帮忙看看 这个代码为什么不会循环" ></div><div class="content"><div class="wz"><a target="_blank" href="'.$srtpljdz[$i].'">'.$srbbbt[$i].'</a></div><div class="price"><span class="price1">RMB:'.$srbbjg[$i].'</span><span class="price2">¥ '.$szzkj[$i].'</span></div><div class="yishou">已售'.$srxssl[$i].'件</div></div></div><div class="dptj1_coloum1_pic"><a target="_blank" href="'.$srtpljdz[$i].'"><img src="/static/imghw/default1.png" data-src="'.$srtpdz[$i].'" class="lazy" style="max-width:90%".$_MODULE["tpgd"].'px;" .$srtpdz[$i].'" / alt="谁帮忙看看 这个代码为什么不会循环" ></a></div></div>'; }}?></div><?php}?>
Copy after login
为什么div不会循环 我手动复制可以哦 用for就不行了
回复讨论(解决方案)
for($i=0;$i<3;$i++)
for($i=0;$i<$num;$i++)
两个$i了
for($i=0;$i<3;$i++)
for($i=0;$i<$num;$i++)
两个$i了 刚改了 发现不一样啊 复制了好多好多
循环时把变量名注意一下,不要弄重了
if($_MODULE[huoqubaobei]!="4"){ $i=-1; foreach($items as $item){ $i++; $itemUrl = $uriManager->detailURI($item); $itemPicUrl = $item->getPicUrl(310); $itemTitle = $item->title; $itemPrice = $item->price; $itemsoldCount = $item->soldCount;
Copy after login
foreach里的$i每循环一次+1,但你的外层for循环$i不能超过三,所以,你的foreach的$i影响了for的$i,也就循环一次了
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
Two Point Museum: Bungle Wasteland Location Guide
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Two Point Museum: Bungle Wasteland Location Guide
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel

6 Extra Skills Every PHP Developer Should Have

Simplified HTTP Response Mocking in Laravel Tests

Build a React App With a Laravel Back End: Part 2, React

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon
