template使用的问题! 我个人认为是你在进行循环时多循环了。这个问题我在phpe.net上看过,好像是属于块的嵌套循环。里面要注意的是要对上一次循环得到的值进行一次赋空值。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 应该是ustb说的 进行一次赋空值 这儿有个例子 $tpl->set_file('forumlist','tpl_forumlist.htm'); $tpl->set_block("forumlist","ROW","rows"); $tpl->set_block("ROW","ADMINLIST","admins"); foreach($flist as $id=>$fdata){ $tpl->set_var("admins"); foreach($fdata as $key=>$value){ if($key=="fadmins"){ $admins[]=explode("¤",$value);//¤ unset($fdata[$key]); } if($key=="flptime")$value=formatTime($value); $tpl->set_var(strtoupper($key),$value); } foreach($admins[$id] as $admin){ $tpl->set_var("ADMIN",$admin); $tpl->parse("admins","ADMINLIST",true); } $tpl->parse("rows","ROW",true); } $tpl->pparse("out","forumlist"); 以下是我写的代码,麻烦各位给看看:#==================================================# 将查询结果输出至模板#----------------------------------------------------------------$template = new template();$template->set_file("file_handle","template/db_result.htm");$template->set_var("Title", $vTitle);$template->set_var("BackColor", "#0066CC");//得到列表的栏目(列)$template->set_block("file_handle","BLOCK_List_Name","ListName");foreach( $aLs as $key => $value){ $template->set_var("List_Name", $key); $template->parse("ListName","BLOCK_List_Name", true);}//得到列表的内容(行)$template->set_block("file_handle","BLOCK_RESULT","AllData");$template->set_block("BLOCK_RESULT","BLOCK_List_Data","ListData");$i = 0;while ( !$result->EOF ){ if ( ($i % 2) == 1 ){ $color = "#FFFFFF"; } else{ $color = "#F2F2F2"; } unset($aLs); $aLs = $result->fields; $vNum = $result->RecordCount(); for( $i=0; $i <=$vNum; $i++){ $template->set_var("Data", $aLs[$i]); $template->parse("ListData","BLOCK_List_Data",true); } $result->MoveNext(); $i++; $template->set_var("BackColor",$color); $template->set_var($out_result); $template->parse("AllData", "BLOCK_RESULT", true);}//数据输出 $template->parse("out", "file_handle"); $template->p("out");$db->Close(); PHP超级菜鸟请教 PHP 的move_uploaded_file问题 PHP连接PostgreSQL代码? 目前LAMP哪几个版本搭配起来好一点 PHP 类问题,为什么成员变量赋值了,输出时没有任何东西? 请问php中有没有哪个函数可以判断出某个值是这个数组的最后一个值 ci分页类,怎么把显示的数字(上页、下页、首页、末页)换成图片显示呢? PHP如何按照指定信息查找另一数据库中同一行的信息。 请问如何将string类型转换成date类型 如何进行模糊查询啊?输入关键字从mysql库中查询包含此关键字的内容... 请教高手mail函数发送图片附件的问题? 不同页面之间的form的数据传递
$tpl->set_file('forumlist','tpl_forumlist.htm');
$tpl->set_block("forumlist","ROW","rows");
$tpl->set_block("ROW","ADMINLIST","admins");
foreach($flist as $id=>$fdata){
$tpl->set_var("admins");
foreach($fdata as $key=>$value){
if($key=="fadmins"){
$admins[]=explode("¤",$value);//¤
unset($fdata[$key]);
}
if($key=="flptime")$value=formatTime($value);
$tpl->set_var(strtoupper($key),$value);
}
foreach($admins[$id] as $admin){
$tpl->set_var("ADMIN",$admin);
$tpl->parse("admins","ADMINLIST",true);
}
$tpl->parse("rows","ROW",true);
}
$tpl->pparse("out","forumlist");
# 将查询结果输出至模板
#----------------------------------------------------------------$template = new template();$template->set_file("file_handle","template/db_result.htm");$template->set_var("Title", $vTitle);
$template->set_var("BackColor", "#0066CC");
//得到列表的栏目(列)$template->set_block("file_handle","BLOCK_List_Name","ListName");foreach( $aLs as $key => $value){
$template->set_var("List_Name", $key); $template->parse("ListName","BLOCK_List_Name", true);
}//得到列表的内容(行)$template->set_block("file_handle","BLOCK_RESULT","AllData");
$template->set_block("BLOCK_RESULT","BLOCK_List_Data","ListData");
$i = 0;
while ( !$result->EOF ){ if ( ($i % 2) == 1 ){
$color = "#FFFFFF";
}
else{
$color = "#F2F2F2";
} unset($aLs);
$aLs = $result->fields;
$vNum = $result->RecordCount(); for( $i=0; $i <=$vNum; $i++){ $template->set_var("Data", $aLs[$i]); $template->parse("ListData","BLOCK_List_Data",true); }
$result->MoveNext(); $i++;
$template->set_var("BackColor",$color);
$template->set_var($out_result); $template->parse("AllData", "BLOCK_RESULT", true);
}//数据输出 $template->parse("out", "file_handle"); $template->p("out");
$db->Close();