我个人认为是你在进行循环时多循环了。
这个问题我在phpe.net上看过,好像是属于块的嵌套循环。
里面要注意的是要对上一次循环得到的值进行一次赋空值。

解决方案 »

  1.   

    应该是ustb说的 进行一次赋空值
      

  2.   

    这儿有个例子
    $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");
      

  3.   

    以下是我写的代码,麻烦各位给看看:#==================================================
    #                          将查询结果输出至模板
    #----------------------------------------------------------------$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();