Problem mit smarty und datenbank.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem mit smarty und datenbank.

    So ich will meine ganzen Skripte die ich mal gecodet haben nun in templates umsetzten. Als klasse verwende ich smarty und nun ist folgendes problem aufgetreten. Funktoniert soweit alles nur wenn ich Datenbanksetze ausgeben will wird immer nur der letzte satz ausgegeben aber nicht die ganze sätzte. Was machen ich falsch hab mal den code gepostet.


    PHP Code:
    <?php
    include('config.inc.php');
    define('SMARTY_DIR','/is/htdocs/wp1009673_FMKUCXMAF1/www/libs/');
    require(
    SMARTY_DIR.'Smarty.class.php');
    $smarty = new Smarty
     
    $smarty->template_dir '//is/htdocs/wp1009673_FMKUCXMAF1/www/Link/templates/';
    $smarty->compile_dir '/is/htdocs/wp1009673_FMKUCXMAF1/www/Link/templates_c/';
    $smarty->config_dir '/is/htdocs/wp1009673_FMKUCXMAF1/www/Link/configs/';
    mysql_connect($sqlhost,$sqluser,$sqlpass) OR DIE( "Couldn't connect to MySQL server!"); 
    mysql_select_db($database); 
    $query "SELECT cate FROM $linkskat    ";
    $ergebn2 mysql_query($query); 


    while (
    $row mysql_fetch_assoc($ergebn2)) {
    $news $row ;

    }
    $smarty->assign('tiel'$news); 
    $smarty->assign('name''Progman');

    $smarty->display('templat.tpl');
    ?>
    Last edited by Victorious; 13-11-2005, 13:16.

  • #2
    du nase ... du solltest deine zuweisungen an smarty auch INNERHALB der schleife machen ....
    INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


    Comment


    • #3
      selbst wenn ich das mache geht es nicht

      Comment


      • #4
        append
        INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


        Comment


        • #5
          was? das ganze hilft mir auch ned weiter

          Comment


          • #6
            http://smarty.php.net/manual/en/api.append.php
            INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


            Comment


            • #7
              hm endweder ich bin völlig blöd oder ka. mit dem befehl zeigt er mir nix mehr an

              Comment


              • #8
                dann solltest du deinen aktuellen code unter rücksichtname von http://www.php-resource.de/forum/sho...threadid=50454 noch einmal posten.

                dein template wäre in diesem zusammenhang auch nicht verkehrt.
                INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


                Comment


                • #9
                  Ich habe es nun so verändert.

                  PHP Code:
                  <?php
                  include('config.inc.php');
                  define('SMARTY_DIR','/is/htdocs/wp1009673_FMKUCXMAF1/www/libs/');
                  require(
                  SMARTY_DIR.'Smarty.class.php');
                  $smarty = new Smarty
                   
                  $smarty->template_dir '//is/htdocs/wp1009673_FMKUCXMAF1/www/Link/templates/';
                  $smarty->compile_dir '/is/htdocs/wp1009673_FMKUCXMAF1/www/Link/templates_c/';
                  $smarty->config_dir '/is/htdocs/wp1009673_FMKUCXMAF1/www/Link/configs/';
                  mysql_connect($sqlhost,$sqluser,$sqlpass) OR DIE( "Couldn't connect to MySQL server!"); 
                  mysql_select_db($database); 
                  $query "SELECT cate FROM $linkskat    ";
                  $ergebn2 mysql_query($query); 

                  $news =array();
                  while (
                  $row mysql_fetch_assoc($ergebn2)) {
                  $news[] = $row ;
                  $smarty->append('tiel'$news); 
                  }

                  $smarty->append('name''Progman');

                  $smarty->display('templat.tpl');
                  ?>
                  Und mein templat sieht so aus

                  PHP Code:
                  {$tiel.cate
                  Last edited by Victorious; 13-11-2005, 13:10.

                  Comment


                  • #10
                    du bist voll mein held. du korrigierst was, und noch viel mehr.... stichwort $news -> $news[]
                    dann brauchst du das append auch nciht mehr und kann $news NACH der schleife zuweisen.

                    du gibt in deinem template eine variable aus, die nicht nicht deine news beinhalten kann ..... tipp: {foreach} bzw..... {$tiel[0].cate}
                    INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


                    Comment


                    • #11
                      $news ist ein numerisches array und besitzt kein indize das "cate" heißt...
                      Für alle die Fehler suchen, gibts gratis tolle Debuggingmöglichkeiten:
                      var_dump(), print_r(), debug_backtrace und echo.
                      Außerdem gibt es für unsere Neueinsteiger ein hervorragendes PHP Tutorial zu PHP 4 und PHP 5 (OOP)
                      Es heißt $array['index'] und nicht $array[index]! Und nein, das ist nicht egal!
                      Dieses Thema lesen, um Ärger im Forum und verzögerte Hilfen zu vermeiden.

                      Comment


                      • #12
                        So es hat nun endlich geklapt mit {foreach}, es klapt zwar immer noch nicht so wie ich es will, aber er gibt nun alles aus. Das neue Problem was aufgetreten ist er mir für alle Kategorien einfach alles ausgibt. Alos zb.
                        Kategorie: Fan page-> link zu fan page
                        Offizielle->link zur offizielen
                        und nicht wie er es jetzt macht
                        Fan page ->link zu fan page und offiziele
                        Offiziele-> link zu offiziele und fan page.

                        Ich weiss nun nicht ob es im Templat der Fehler ist oder in der php datei.
                        Der code von der index.php sieht so aus
                        PHP Code:
                        <?php
                        $query 
                        "SELECT cate FROM $linkskat    ";
                        $ergebn2 mysql_query($query); 

                        while (
                        $row mysql_fetch_array($ergebn2)) {
                        $cate $row ;
                        $smarty->append('tiel'$cate); 

                        $query "SELECT * FROM koosai_links WHERE kat='$cate[cate]'   ORDER BY userid ";
                        $ergebn mysql_query($query); 

                        while (
                        $dat mysql_fetch_array($ergebn)) {
                        $link $dat ;

                        $smarty->append('name'$link);
                        }
                        }

                        ?>
                        und für die Template sieht so aus:
                        PHP Code:

                        <html>
                        <
                        body>
                        {foreach 
                        from=$tiel  item=tietel}
                        {
                        $tietel.cate}
                        {foreach 
                        from=$name  item=name2}
                        <
                        A href='http://{$name2.link}'  target='_blank'>{$name2.name}</a></td>
                        {
                        $name2.besch}
                        {/foreach}
                        {/foreach} 
                        Last edited by Victorious; 14-11-2005, 18:08.

                        Comment


                        • #13
                          Pass mal auf, ich kann Hellsehen:

                          Du wirst gleich die FORUMSREGELN lesen und anschließend sofort deinen Code umbrechen.

                          Dann wirst du eine göttliche Eingebung erfahren und deine While-Schleifen nochmal überdenken, damit $cate und $link nicht immer nur überschrieben werden.


                          Na, hab ich Recht?

                          Comment


                          • #14
                            Hm ich habe das nun mal komplet überdacht komme aber nicht auf den fehler.
                            Hab das mal in das verändert.
                            PHP Code:
                            $query "SELECT cate FROM $linkskat    ";
                            $ergebn2 mysql_query($query); 

                            while (
                            $row mysql_fetch_array($ergebn2)) {
                            $cate $row ;
                            $catid $row['cate'];
                            $smarty->append('tiel'$cate); 

                            $query1 "SELECT * FROM koosai_links WHERE kat='$catid'   ORDER BY userid ";
                            $ergebn mysql_query($query1); 

                            while (
                            $dat mysql_fetch_array($ergebn)) {
                            $link $dat ;

                            $smarty->append('name'$link);
                            }

                            Comment

                            Working...
                            X