所以不是你的循环的错误,而是你数据库查询代码位置的错误
要这样写
$num=mysql_query("select
*
from
china_city
where
parentid=0")
$n=
mysql_num_rows
($num)
for($i=1$i<=$n$i++){
${"row".$i}=mysql_fetch_array($num)
echo
$i."
".${"row".$i}['city']."
"
}
一般都是用foreach或while写的
foreach(mysql_fetch_array($num)
as
$key=>$value){}
while($row
=mysql_fetch_array($num)){}
for (Device dev : list) {String dmi = dev.getDeviceModelId()
if (StringUtils.isBlank(dmi)){
continue
}
DeviceModel dm = this.deviceModelManager.get(dmi)//查询数据库
dev.setDeviceModel(dm)
}
代码块二:
List<String>deviceModelIdList = new ArrayList<String>()
for (Device dev : list) {
String dmi = dev.getDeviceModelId()
if (StringUtils.isBlank(dmi)){
continue
}
deviceModelIdList.add(dmi)
}
List<DeviceModel>deviceModelList = this.deviceModelManager.find(new NameValuePair("id", MatchMode.IN, deviceModelIdList))//查询数据库
for (Device dev : list) {
for(DeviceModel model : deviceModelList){
if(model.getId().equals(dev.getDeviceModelId())){
dev.setDeviceModel(model)
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)