Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Gästebuch Template mit Smarty

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
Webbi
Smarty n00b


Joined: 14 Nov 2004
Posts: 1

PostPosted: Sun Nov 14, 2004 3:18 pm    Post subject: Gästebuch Template mit Smarty Reply with quote

hi,

wie der titel schon sagt, möchte ich ein template für mein Gästebuch erstellen.

Das Problem daran ist die while schleife Sad

ich stelle hier jetzt einen ganz einfach und verkürzten Code rein als Beispiel:

Das Template (guestbook.tpl)
Code:

<form name="gb_eintragen" method="post" action="gb.php">
 
  <p>Name: 
    {$name}
    <br>
    E-Mail:
    {$email}
    <br>
    Eintrag:
    {$eintrag}
   <br>
   <br>
    {$submit}
  </p>
</form>

<p><b>{$ausgabe_name}</b> hat am {$time} folgendes hinterlassen:</p>
<p><i>{$ausgabe_eintrag}</i></p>
<hr>


PHP-Script: (guestbook.php)
[php:1:16a7a98312]
<?php

@mysql_connect('HOST', 'USER', 'PASS');
mysql_select_db('DATABASE');

require('smarty/Smarty.class.php');
$smarty = new Smarty;
require('config/bbcode.php');

/* Eingabefelder */

$smarty->assign('name', '<input name="name" type="text" id="name">');
$smarty->assign('email', '<input name="email" type="text" id="email">');
$smarty->assign('eintrag', '<textarea name="eintrag" id="eintrag"></textarea>');
$smarty->assign('submit', '<input type="submit" name="submit" value="Senden">');

/* Ausgabe der Gästebuch Einträge */

$result = mysql_query('SELECT * FROM guestbook ORDER BY ID DESC;');
while($row = mysql_fetch_assoc($result))
{
if(!empty($row['email']))
{
$smarty->assign('ausgabe_name', '<a href="mailto:'.$row['email'].'">'.$row['name'].'</a>');
} else {
$smarty->assign('ausgabe_name', $row['name']);
}
$smarty->assign('time', date("D M d, Y g:i a", $row['time']));
$smarty->assign('ausgabe_eintrag', bbcode(htmlspecialchars($row['eintrag'])));
}
?>
[/php:1:16a7a98312]

Also, bei diesem Code währe es schwachsinig, ein templatesystem anzuwenden, aber das ist nicht der richtige Code, meiner ist sehr viel größer, besser formatiert, und enthält noch mehr ausgabe wie z.B. ICQ, Herkunft, Homepage.

Aber als Beispiel reicht dieser.

Ok mein Problem:

die while schleife liest zwar jeden eintrag aus der Datenbank, aber das Template kann nur einen einzigen Eintrag zeigen.

Also bräuchte ich noch ne while Schleife im Template.

Nur wie geht das ?

Ich benutze noch nicht alzulang smarty ( gerade mal ein paar Tage )
Für die Documentation hatte ich leider noch keine Zeit Sad .

Ich hoffe ihr könnt mir helfen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Mon Nov 15, 2004 7:21 am    Post subject: Re: Gästebuch Template mit Smarty Reply with quote

Code:

<form name="gb_eintragen" method="post" action="gb.php">
 
  <p>Name: 
    {$name}
    <br>
    E-Mail:
    {$email}
    <br>
    Eintrag:
    {$eintrag}
   <br>
   <br>
    {$submit}
  </p>
</form>
{ foreach from=$entrys item="entry"}
<p><b>{$entry.name}</b> hat am {$entry.time} folgendes hinterlassen:</p>
<p><i>{$entry.text}</i></p>
{ /foreach }
<hr>



[php:1:fd3b8cfd16]
<?php

@mysql_connect('HOST', 'USER', 'PASS');
mysql_select_db('DATABASE');

require('smarty/Smarty.class.php');
$smarty = new Smarty;
require('config/bbcode.php');

/* Eingabefelder */

$smarty->assign('name', '<input name="name" type="text" id="name">'); // sowas hier gehört ins Template!
$smarty->assign('email', '<input name="email" type="text" id="email">');// sowas hier gehört ins Template!
$smarty->assign('eintrag', '<textarea name="eintrag" id="eintrag"></textarea>');// sowas hier gehört ins Template!
$smarty->assign('submit', '<input type="submit" name="submit" value="Senden">');// sowas hier gehört ins Template!

/* Ausgabe der Gästebuch Einträge */

$result = mysql_query('SELECT * FROM guestbook ORDER BY ID DESC;');
$entrys = array();
while($row = mysql_fetch_assoc($result))
{
$entrys[] = $row;
/* Das folgende Zeug gehört alles ins Template:
if(!empty($row['email']))
{
$smarty->assign('ausgabe_name', '<a href="mailto:'.$row['email'].'">'.$row['name'].'</a>');
} else {
$smarty->assign('ausgabe_name', $row['name']);
}
$smarty->assign('time', date("D M d, Y g:i a", $row['time']));
$smarty->assign('ausgabe_eintrag', bbcode(htmlspecialchars($row['eintrag'])));*/
}
$smarty->assign('entrys', $entrys);
?>
[/php:1:fd3b8cfd16]
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP