模板改为
//tpl.htm
<table>
<tr><td>查询结果为</td></tr>
<!-- BEGIN row -->
<tr><td>{name}</td></tr>
<!-- END row -->
</table>程序
....  for($i=0;$i<$num;$i++)
  {
    $temp->set_var(array("id"=>$id[$i],"name"=>$name[$i]));   //??????????????????也不懂!!!这里给两个模板变量赋值,虽然模板中只有一个变量。做了无用功,呵呵
    $temp->parse("rows","row",true);
  }
  $temp->parse("out","handle");
  $temp->p("out");
?>

解决方案 »

  1.   

    还是不行啊,提示
    Template Error: loadfile: row is not a valid handle.
    Halted.
      

  2.   

    <?php
    require("./class/funcs.php");  //一些数据库连接函数
    require("./class/template.php");  //phplib中template.inc,我只是改了一下名字
    $temp=new Template("./templates/default");  //模板所在目录
    $mylink=dbconnect();/* 查询 */
    $sql    = "select * from $test";
    $result = mysql_query($sql);
    $temp->set_file("handle","test.htm");//设置文件句柄
    $temp->set_block("handle","rowlist","rows");//设置块,命名规则:第一个参数是页面句柄,第二个是块名,第三个是块的别名
    while($obj=mysql_fetch_object($result))
    {
        $temp->set_var(array("id"=>$obj->id,"name"=>$obj->name));
        $temp->parse("rows","rowlist",true);//设置true即为追加
    }
    $temp->parse("rows","handle");//循环结束,将文件句柄解析
    $temp->p("rows");//输出
    ?>//test.htm
    <table>
    <tr><td>查询结果为</td></tr>
    <!-- BEGIN rowlist -->
    <tr><td>{id}{name}</td></tr>
    <!-- END rowlist -->
    </table>
      

  3.   

    555555,我真笨啊,还是出错,不好意思啊,是不是我哪个单词写错了?
    错误提示是:
    Template Error: loadfile: rowlist is not a valid handle.
    Halted.//test.htm
    <table width="90%" border="1"> <tr><td><div align="center">搜索结果</div></td></tr> 
    <!--BEGIN rowlist --> <tr><td width=15%>{id}{name}</td></tr> <!--END rowlist --> 
    </table>//test.php
    <?
      require("./class/funcs.php");
      require("./class/template.php");
      $temp=new Template("./templates/default");
      $mylink=dbconnect();
      $sql="select * from $test";
      $result=mysql_query($sql);
      $temp->set_file("handle","test.htm");
      $temp->set_block("handle","rowlist","rows");
      while($obj=mysql_fetch_object($result))
      {
        $temp->set_var(array("id" => $obj->id,"name" => $obj->name));
        $temp->parse("rows","rowlist",true);
      }
      $temp->parse("rows","handle");
      $temp->p("rows");
    ?>
      

  4.   

    你的phplib的版本是多少。
    给个地址去下一个吧
    http://c994.8189.net/phplib.rar
      

  5.   

    不知道是不是命名冲突改成这样试试
    $temp->parse("out","handle");//循环结束,将文件句柄解析
    $temp->p("out");//输出
      

  6.   

    知道了,
    看你的模板,
    BEGIN,END之前得有一个空格,如果没有空格肯定会出问题。
    我给你的模板没有问题,你把空格给去掉了。
    你可以修改一下phplib中的template类中的正则表达式。