模板改为
//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");
?>
//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");
?>
Template Error: loadfile: row is not a valid handle.
Halted.
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>
错误提示是:
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");
?>
给个地址去下一个吧
http://c994.8189.net/phplib.rar
$temp->parse("out","handle");//循环结束,将文件句柄解析
$temp->p("out");//输出
看你的模板,
BEGIN,END之前得有一个空格,如果没有空格肯定会出问题。
我给你的模板没有问题,你把空格给去掉了。
你可以修改一下phplib中的template类中的正则表达式。