Wie kann ich diese Schleife mit tmpl umsetzen ?

E

elgo

hallo

ich hab hier eine kleine schleife zum auslesen von daten

PHP:
require("../config/dbconnect.php");

$query_topic = "SELECT * FROM forum_topic ORDER BY topic_id";
$result_topic = mysql_query($query_topic);
while ($row = mysql_fetch_array($result_topic)){
    
	$topic_id = $row[topic_id];
	$topic_title = $row[topic_title];
	
	print "<a href=?tid=" . $topic_id . ">" . $topic_title . "</a><br>";
	
	if($tid == $topic_id){
	
		$query_post = "SELECT * FROM forum_post WHERE topic_id='" . $tid . "' ORDER BY post_id";
		$result_post = mysql_query($query_post);
		while ($row1 = mysql_fetch_array($result_post)){
		
		$post_subject = $row1[post_subject];
		
		print $post_subject . "<br>";
			
			}
	
		}
		
	}

die funktioniert auch ohne problem , allerdings will ich das ganze mit templates umsetzten und das macht mir probleme

hier mal mein ansatz:

PHP:
require("../config/dbconnect.php");
include("../include/patTemplate.php");

$tmpl = new	patTemplate();

$tmpl->setBasedir( "../templates/" );

$tmpl->readTemplatesFromFile( "view.tmpl.html" );

$query_topic = "SELECT * FROM forum_topic ORDER BY topic_id";
$result_topic = mysql_query($query_topic);
while ($row = mysql_fetch_array($result_topic)){
	
	$tmpl->addVar("topics", "TID", $row[topic_id]);
	$tmpl->addVar("topics", "TTITLE", row[topic_title]);

	if($tid == $topic_id){
	
		$query_post = "SELECT * FROM forum_post WHERE topic_id='" . $tid . "' ORDER BY post_id";
		$result_post = mysql_query($query_post);
		while ($row1 = mysql_fetch_array($result_post)){
		
		$tmpl->addVar("posts", "PSUBJECT", $row[post_subject]);
		
                  $tmpl->parseTemplate("posts", "a");

	
			}
	
		}
		
	$tmpl->parseTemplate("topics", "a");
	
	}

$tmpl->displayParsedTemplate(  );

hier die dazugehörige view.tmpl.html

Code:
<patTemplate:tmpl name="topics">

<a href="?tid={TID}">{TTITLE}</a><br>
<patTemplate:tmpl name="posts">

{PSUBJECT}<br>

</patTemplate:tmpl> 


</patTemplate:tmpl>

hat irgend jemand eine idee ?
 
ahh

ok , vielen dank erstmal

wenn sich jemand mit PatTemplate auskennt & schon mal ein ähnliches problem hatte kann er hier ja nochmal posten

oder kenn jemand vielleicht noch andere leicht zu bedienende tmplsysteme
 
Man muss dazu sagen dass Smarty in der Templatestruktur sehr komplex sein kann.

So ist es z.b. möglich ein Array an Smarty zu übergeben und diese mit einer foreach schleife (direkt im template) auszugeben.

Hier mal ein kleines beispiel:
Erstmal die Variablenübergabe an Smarty
PHP:
$smarty->assign("kontakte", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
      array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));

und schliesslich die Ausgabe im Template

Code:
{foreach name=aussen item=kontakt from=$kontakte}
  {foreach key=schluessel item=wert from=$kontakt}
    {$schluessel}: {$wert}<br>
  {/foreach}
{/foreach}

AUSGABE:

phone: 1<br>
fax: 2<br>
cell: 3<br>
phone: 555-4444<br>
fax: 555-3333<br>
cell: 760-1234<br>
 
da ich smarty selbst auf vielen Seiten einsetze, kann ich dir auch nur die Mailingliste ans Herz legen, über die du auch schnell an Antworten kommst, wenn dir die OnlineDoku nicht weiterhelfen sollte.
 
Zurück