ERLEDIGT
JA
JA
ANTWORTEN
4
4
ZUGRIFFE
1834
1834
EMPFEHLEN
-
05.01.11 12:55 #1
Ich versuch momentan Smarty zu lernen und kann's auch zum Teil schon umsetzen.
Mein Testscript ist ein Gästebuch-Backend.
Erst hab ich es recht einfach programmiert und das funktioniert auch schon tadellos - jetzt will ich sämtlichen HTML-Code aus den PHP-Dateien entfernen, bei einem einzelnen Eintrag klappt das auch - nur funktioniert das noch nicht ganz bei der Eintragsliste die ich aus der Datenbank auslese.
So hatte ich das bisher:
Und so versuche ich es jetzt:PHP-Code:$DbCon->DoSql("SELECT gbook_id,name,email,url,text,timestamp FROM ".$tblgbook." ORDER BY gbook_id DESC ");
$gbook_content .= "<table border=\"0\" cellspacing=\"0\" cellpadding=\"5\" width=\"100%\" class=\"zebra\">";
while ($row = $DbCon->GetRes()) {
$gbook_content .= '<tr title="'.htmlspecialchars($row['text']).'">
<td>'.$row['gbook_id'].'</td>
<td>'.$row['name'].'</td>
<td>'.$row['email'].'</td>
<td>'.$row['url'].'</td>
<td>';
$gbook_content .= date_return($row['timestamp']);
$gbook_content .= '</td>
<td>[<a href="index.php?link=au_gbook&job=edit&id='.$row['gbook_id'].'">Edit</a>]</td>
<td>[<a href="index.php?link=au_gbook&job=del&id='.$row['gbook_id'].'">Delete</a>]</td>
</tr>';
}
$gbook_content .= "</table>";
gbook_list.tpl
au_gbook.phpPHP-Code:<table border="0" cellspacing="0" cellpadding="5" width="100%">
{foreach name=aussen item=guestbok from=$guestbook}
{foreach key=gid item=gbook from=$guestbok}
<tr title="{$gbook.text}">
<td>{$gid}</td>
<td>{$gbook.name}</td>
<td>{$gbook.email}</td>
<td>{$gbook.url}</td>
<td>{$gbook.timestamp}</td>
<td>[<a href="{$gbook.edit}">Edit</a>]</td>
<td>[<a href="{$gbook.delete}">Delete</a>]</td>
</tr>
{/foreach}
{/foreach}
</table>
Das Problem das ich hierbei habe ist:PHP-Code:$DbCon->DoSql("SELECT gbook_id,name,email,url,text,timestamp FROM ".$tblgbook." ORDER BY gbook_id DESC ");
$smarty->assign("guestbook", $DbCon->GetRes());
$smarty->fetch('gbook_list.tpl');
1. das ich ein Feld {$guestbook} in meinem Main-Template brauche - ich würd das gerne aber wieder über die {$content} einbinden. Zum anderen scheint er auch das template so nicht zu finden das er hier halt einbinden soll.
2. wenn ich $smarty->display('gbook_list.tpl'); statt fetch nehme zeigt er mir mein Template zwar an, aber über dem Design und mit komischen werten die sich in jeder zeile wiederholen
Ich hab wahrscheinlich nur einen Denkfehler in meinem Script, aber komm momentan grad nicht selber drauf.^-_-^Mata ne
Supercat1510
-
06.01.11 00:49 #2
Tja - nach etlichen Versuchen doch noch geschafft:
gbook_list.tpl:
au_gbook.phpPHP-Code:{config_load file=test.conf section="setup"}
<table border="0" cellspacing="0" cellpadding="5" width="100%" class="zebra">
{foreach key=gid item=gbook from=$content}
<tr title="{$gbook.text|htmlentities}">
<td>{$gid.id}</td>
<td>{$gbook.name|htmlentities}</td>
<td>{$gbook.email}</td>
<td>{$gbook.url}</td>
<td>{$gbook.timestamp}</td>
<td>[<a href="index.php?link=au_gbook&job=edit&id={$gid}">Edit</a>]</td>
<td>[<a href="index.php?link=au_gbook&job=del&id={$gid}">Delete</a>]</td>
</tr>
{/foreach}
</table>
Vielleicht brauchts ja jemand.PHP-Code:$DbCon->DoSql("SELECT gbook_id,name,email,url,text,timestamp FROM ".$tblgbook." ORDER BY gbook_id DESC ");
while ($row = $DbCon->GetRes()) {
$liste[] = $row;
}
$gbook_content .= $smarty->assign("content", $liste);
$gbook_content .= $smarty->fetch('gbook_list.tpl');
^-_-^Mata ne
Supercat1510
-
ich hab nen ähnlöiches problem:
room.php
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
else if($action == "searchroom" && $login) { $tmpl_name = "frameset.tpl"; $Smarty->append("css","fenster.css"); $Smarty->assign("titlevar", Url("index.php?action=menu_login")); $Smarty->assign("menubar", Url("room.php?action=littlemenu")); $Smarty->assign("content", Url("room.php?action=searchroommain")); $Smarty->assign("Raumverwaltung - Raumsuche", $tmpl_titel); } else if($action = "searchroommain" && $login) { $Smarty->append("css","fenster.css"); $Smarty->append("css","formular.css"); $tmpl_name = "fenster.tpl"; $Smarty->assign("popheadleft","<p>Raum suchen</p>"); $Smarty->assign("popheadright","img/search.png"); $formular = '<div class = "formular"><form action = "room.php?action=dosearchroom" method = "POST">'; $formular .= '</br><div class = "formularleft">Raumsuche: </div>'; $formular .= '<div class = "formularright"><input type = "text" name = "Raumsuche"></div>'; $formular .= '<input type = "submit" class="ok" value = "Suchen">'; $formular .= '</form>'; $formular .= formular("room.php?action=start","abbrechen",NULL,"ok"); $formular .= '</div>'; $data = $Controller->Raum->Search($_POST["Raumsuche"]); while ($row = $data) { $liste[] = $row; } $data_content .= $smarty->assign('popmainup', $liste); $data_content .= $smarty->fetch('searchroom.tpl'); var_dump($data); //$Smarty->assign('popmainup',$data_content); }
searchroom.tpl
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<div id = "popheadright"><img src="img/key.png" title="Symbol" alt="Symbol" /></div> </div> <div id="popmain"> <div id="popmainup"><br /> <form> {config_load file=test.conf section="setup"} <table border="0" cellspacing="0" cellpadding="5" width="100%" class="zebra"> {foreach key=data item=gbook from=$data} <tr> <td>{$data.id}</td> </tr> {/foreach} </table> </form> </div> <div id="popmaindown"></div> </div> </div> </div>
kann mir vielleicht jemand sagen, wie ich die tabelle, die in einer db gespeichert hab auslesen kann****?
$data liest die db aus..
-
17.02.11 07:26 #4
Deine Foreach-Abfrage müsste so aussehen:
Kurz zum Verständnis:PHP-Code:{foreach key=data item=gbook from=$popmainup}
<tr>
<td>{$gbook.id}</td>
</tr>
{/foreach}
Du speicherst deine Daten für das Foreach in $liste und liest dann diese mit popupmain ins smarty.
PHP-Code:$data = $Controller->Raum->Search($_POST["Raumsuche"]);
while ($row = $data)
{
$liste[] = $row;
}
$data_content .= $smarty->assign('popmainup', $liste);
^-_-^Mata ne
Supercat1510
-
hat geklappt, danke
Ähnliche Themen
-
Daten aus Datenbank auslesen
Von webhoster im Forum PHPAntworten: 10Letzter Beitrag: 07.08.11, 23:19 -
[Smarty] Problem mit Foreach... Array gibt flasche Daten aus
Von Elmo im Forum PHPAntworten: 3Letzter Beitrag: 18.11.08, 14:45 -
Smarty Array (Datenbank) Daten einlesen
Von =fire= im Forum PHPAntworten: 0Letzter Beitrag: 12.10.07, 20:48 -
smarty: wird {foreach} ausgeführt?
Von mille im Forum PHPAntworten: 1Letzter Beitrag: 01.08.05, 22:55 -
[Smarty-Template]: Foreach-Problem / -Frage
Von DirkHo im Forum PHPAntworten: 0Letzter Beitrag: 01.03.05, 22:01





Zitieren
Login






[PHP][Snippet] Array zu XML konvertieren