2011-03-31 113 views
0

我使用模板系統在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://stackoverflow.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

回答

2

編輯:好的,你正在使用一種叫做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