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

Ausgabe

 
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
builder24
Smarty Rookie


Joined: 28 Nov 2004
Posts: 6

PostPosted: Sun Nov 28, 2004 4:05 pm    Post subject: Ausgabe Reply with quote

Hallo,

ich scheitere an einer einfachen Ausgabe Sad

meine PHP-Datei:
[php:1:933dac76ff]<?php
$news = $db->dbQuery("SELECT * FROM ".DBTAB_NEWS."");
while($row_news = mysql_fetch_array($news))
{
$row_news[id];
$row_news[titel];
}
$smarty->assign('newstitel', $row_news['titel']);
$smarty->display('index.tpl');
?>[/php:1:933dac76ff]

Template:
Code:
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td>News</td>
      </tr>
{foreach from=$row_news item=titel}
      <tr>
        <td>&{$newstitel}</td>
      </tr>
{/foreach}       
    </table>


Was mache ich falsch?
Back to top
View user's profile Send private message
T.
Smarty Regular


Joined: 22 Aug 2004
Posts: 69
Location: AT

PostPosted: Sun Nov 28, 2004 6:18 pm    Post subject: Reply with quote

mir ist absolut nicht klar, was du mit deinem php code bezweckst
$row_news[id];
$row_news[titel];

hä? sollte da nicht ne zuweisung stattfinden? bzw. braucht die schleife überhaupt wer?

naja, wie auch immer. Wink

Das dein Code nicht funktioniert liegt eigentlich auf der Hand. Also Manual lesen! (jetz hätt ich scho fast Manuel gschrieben, tztztz).

du willst in smarty auf die variable $row_news zugreifen. hast du die übergeben per assign? nein! Wink kann ja ned gehen. du hast zwar ein array aus titel übergeben (falls das ein array is), aber an die variable "newstitel" assigned. also kannst du nur auf die variable newstitel zugreifen.

Wie foreach und sections funktionieren kannst du in der doku und per Forumsuche nachlesen Wink

mfg Thomas
_________________
Oppossom - Heavy rock from austria
Back to top
View user's profile Send private message Visit poster's website
builder24
Smarty Rookie


Joined: 28 Nov 2004
Posts: 6

PostPosted: Mon Nov 29, 2004 5:33 pm    Post subject: Reply with quote

Quote:
du willst in smarty auf die variable $row_news zugreifen. hast du die übergeben per assign? nein!

und was mache ich hier?!

[php:1:6ccaf67f7b]<?php $smarty->assign('newstitel', $row_news['titel']); ?>[/php:1:6ccaf67f7b]

Ich verstehe es nicht, weil kein enziges Bsp. in der Doku zu finden ist.
Ein Bsp. mit der while-Schleife wäre sehr hilfreich.
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Nov 29, 2004 6:07 pm    Post subject: Reply with quote

http://smarty.php.net/contribs/examples/mysql/ <-- da ist ein beispiel
Back to top
View user's profile Send private message Send e-mail Visit poster's website
T.
Smarty Regular


Joined: 22 Aug 2004
Posts: 69
Location: AT

PostPosted: Mon Nov 29, 2004 6:09 pm    Post subject: Reply with quote

builder24 wrote:

und was mache ich hier?!

[php:1:55ed69abd0]<?php $smarty->assign('newstitel', $row_news['titel']); ?>[/php:1:55ed69abd0]


nun ja, du weißt der Smarty-Variable newstitel den Wert von $row_news['titel'] zu.

Was du vermutlich tun willst ist folgendes:
<?php $smarty->assign('row_news', $row_news['titel']); ?>

mein code schaut so aus:
$kunden = $db->sql_fetchrowset($db->sql_query($sql))
$smarty->assign("kunden",$kunden);

du wirst nen anderen datenbankzugriff haben, aber sql_fetchrowset gib mir genau ein Array mit allen Werten der aktuellen Abfrage zurück, also
$kunde[0]['Kundenname'] ist erste Zeile Kundenname.
Wie das mit den Stanard-mysqlfunktionen geht - ka, müsst ich nachschauen.

und im template

{section name=i loop=$kunden}
{$kunden[i].Kundenname}<br>
{$kunden[i].Kundennummer}<br><br>
{/section}

und fertig ist der Spaß!

mfg Thomas

[edit]: ich seh grad, ich hätt mir die arbeit sparen können Very Happy[./...]
_________________
Oppossom - Heavy rock from austria
Back to top
View user's profile Send private message Visit poster's website
builder24
Smarty Rookie


Joined: 28 Nov 2004
Posts: 6

PostPosted: Mon Nov 29, 2004 6:53 pm    Post subject: Reply with quote

Ich danke euch Beiden.
Jetzt ist mir alles glasklar Very Happy

Und riesen Dank an messju für das Beispiel.

mfG
builder
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