PHP模板系统输出

问题描述:

我使用模板系统在PHP,所以我的代码就是这样的例子...PHP模板系统输出

$template->addVar ('thenameoftemplate', 'thenameofsubtemplate',"what to output"); 

而在HTML文件中像...... {thenamefsubtemplate}这个代码I输出..

但我有一个问题,当我尝试从模板输出数据库中的东西像上面的例子,但从数据库,它不工作,只有1行输出,但当它回声的外面它的作品模板..

我试着用foreach输出,而eaven用for从数据库并将其输出到模板中,但它只显示一个结果。

如何解决这个问题,我不想将所有的结果排成一列并输出。

更新

Actualy我不知道什么是模板系统,一些脚本gaved对我.. everythingwas确定,直到该数据库输出..

这是我最后一次尝试在对..

if (check_group_access_bool('show_admin_panel_button')) { 
      $template->addGlobalVar('admin','<BR><a href="https://*.com/users/download_list/'. $user[0]['id'] .'.html">виж Ñмъкваните пеÑни</a><BR><img src="/images/icons/edit-user-32x32.png" hspace="2" alt="редактирай" align="absmiddle"><a href="/admin/edit_user/'. $user[0]['id'] .'.html">редактирай</a>'); 
} 
      $sudtwo = $_SESSION['user']['id']; 
$fvsmt = mysql_query("select * from fav where user_id=$sudtwo"); 
if(isset($_SESSION['user']['id'])){ 

while($rowings = mysql_fetch_array($fvsmt)) { 
$template->addVar('userprofile', 'userprofiletwo',"<tr><th nowrap valign=\"TOP\" align=\"LEFT\"> ñòèë: ".$rowings['name']." <form method=\"post\"><input type=\"submit\" value=\"premahni ot liubimi\" name=\"del\"></form>></th></tr>"); 

if(isset($_POST['del'])) 
{ 
mysql_query("DELETE FROM fav WHERE name_id=".$rowings['name_id'].""); 



} 
echo"".$rowings['name']."<br>"; 

} 
} 

这是在PHP和这里是HTML

<template:tmpl name="userprofile"> 
{USERPROFILETWO} 
</template:tmpl> 

这就是它的输出结果。

在php代码中,我的回声在哪里起作用,但这里的html输出只有一行。

+0

什么是你从试图输出数据库?在这里发布代码的相关位。 – JohnP 2011-03-31 09:21:02

+0

您需要向我们展示一些代码以及您正在使用的模板系统。 – ThiefMaster 2011-03-31 09:25:36

+0

它是什么模板?为什么这么秘密? – 2011-03-31 09:28:55

编辑:好的,你正在使用一种叫做patTemplate的东西,它在几年内还没有更新。我发现了一些documentation虽然,一旦你正确设置你的PHP,这在你的HTML应该工作:

<table> 
    <patTemplate:tmpl name="userprofile"> 
    {userprofiletwo} 
    </patTemplate:tmpl> 
</table> 

,但你的PHP是一个有点乱。你有什么主要是:

for() { 
    $rowings = ...; 
    //you are overwriting the variable each time here 
    $template->addVar('userprofile', 'userprofiletwo', $rowings); 
} 

我想你想的是一样的东西:

$rowings = array(); 
for() { 
    // make an array of your data 
    $rowings[] = ...; 
} 
// and call addVar *once* 
$template->addVar('userprofile', 'userprofiletwo', $rowings); 

现在{} userprofiletwo是一个数组,你可以遍历在您的模板。

而且,我不知道这段代码的目的是什么:

if(isset($_SESSION['user']['id'])){ 
} 

,因为它并没有真正做什么...

+0

但是,它会给出错误。 调用未定义的方法patTemplate :: append() – weardstuff 2011-03-31 09:49:16

+0

我发布了该帖子的代码,一些想法? – weardstuff 2011-03-31 10:05:55

+0

没有看到你的模板引擎的代码,没有人可以告诉你如何从数据库中追加行而不是输出单行。 – 2011-03-31 12:53:30