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

Datenbank auslesen

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


Joined: 27 Jun 2013
Posts: 6
Location: Vienna

PostPosted: Wed Jul 03, 2013 2:33 pm    Post subject: Datenbank auslesen Reply with quote

Hallo
möchte Werte aus meiner DB in meine Tabelle einfügen. Hab mal bisschen herum probiert, nicht viel dabei herausgekommen. Die Werte befinden sich in der Spalte "wert" und haben eigentlich eine bestimmte "id" und "monat". Das heißt jeder Wert hat einen bestimmten Platz in der Tabelle. Aber das kann ich später machen, jetzt will ich nur, dass das auslesen der Daten funktioniert.
danke für alle Antwortem, Gruß Very Happy

das tpl file
Code:
{php}
 
 mysql_connect('localhost', 'wwwrun', 'wwwwww');
 mysql_select_db('umsatzvorschau');
 $result = mysql_query("SELECT wert FROM umsaetze");
 
 #$row = mysql_fetch_row($result);
 #$this->assign('extra',$row);
 
{/php}


Code:
{section name=monat start=7 loop=13 step=1}
               
                  <td><input type="text" name="ums_{$projekt.$ONR}_{$smarty.section.monat.index}"  value="{$result}">
                     <br/>
                     <input type="submit" name="button" value="Absenden"></td>
               {/section}
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Thu Jul 04, 2013 7:02 am    Post subject: Reply with quote

1. PHP im Template ist nicht gut und auch nicht wirklich sicher, vorallem wenn du da die DB anfrage machst
2. mysql_fetch_array ist wahrscheinlich besser für dein Vorhaben
3. Was genau willst du machen?
4. Du verwendest in deiner "section" die Variable "extra" doch nicht einmal!
Back to top
View user's profile Send private message Visit poster's website
edepyahu01
Smarty Rookie


Joined: 27 Jun 2013
Posts: 6
Location: Vienna

PostPosted: Thu Jul 04, 2013 9:12 am    Post subject: Reply with quote

hab es jetzt mit mysql_fetch_array() versucht. Ich weiß oder denke zu wissen, dass ich das Assign brauche, daher hab ichs mal geschrieben weiß aber nicht genau wie ich es in der section verwenden soll :S
Das Ziel ist es die Spalte "Wert" aus meiner DB "umsaetze" in der Tabelle im Template auszugeben. Wie du siehst erzeugt die "section" 7 Spalten in der Tabelle mit den Monaten (Juli, August,...) und hier sollen die Werte einzeln eingetragen werden. Später will ich eine if Abfrage einbauen damit es die Werte an die richtige Stelle in der Tabelle einträgt, aber das ist mal Zukunftsmusik.
schaut jetzt so aus:
Code:
require_once ('class.php');
mysql_connect('localhost', 'wwwrun', 'wwwwww');
mysql_select_db('umsatzvorschau');
$result = mysql_query("SELECT wert FROM umsaetze");
 
while($row = mysql_fetch_array //erzeugt Array mit den Werten
($result, MYSQL_NUM)){
   printf();//Parameter füllen!
   
}
$smarty->assign('wert',$row);

nochmal die section:
Code:
{section name=monat start=7 loop=13 step=1}
               
                  <td>
                  <input type="text" name="ums_{$projekt.$ONR}_{$smarty.section.monat.index}" value="{$result}">
                     <br/>
                  <input type="submit" name="button" value="Absenden">
                  </td>
               {/section}
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Thu Jul 04, 2013 9:31 am    Post subject: Reply with quote

Du darfst nicht vergessen die Mysql connection zu schließen. Versuch es damit:

Code:

require_once ('class.php');
$connection = mysql_connect('localhost', 'wwwrun', 'wwwwww');
mysql_select_db('umsatzvorschau');
$result = mysql_query("SELECT wert FROM umsaetze");
$werte = mysql_fetch_array($result)
mysql_close($connection);
$smarty->assign('werte', $werte);


im Template dann über foreach:

Code:

{foreach from=$werte item=wert key=k}
   {* hier mit der Variable $wert arbeiten *}
{/foreach}
Back to top
View user's profile Send private message Visit poster's website
edepyahu01
Smarty Rookie


Joined: 27 Jun 2013
Posts: 6
Location: Vienna

PostPosted: Thu Jul 04, 2013 1:33 pm    Post subject: Reply with quote

keine Fehler Smile
vielen Dank, Gruß Very Happy
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