Witam Ponownie

Juz nie trzeba pomocy poradzilem sobie mozna skasowac ... itd


A wiec mam problem z wyświetlaniem wszsytkich newsów.
(oczywiscie w bazie mam 2 newsy i chce aby sie wyswietily)

news.php
  1. <?php
  2. include 'config.php';
  3. include 'template/template.inc.php';
  4.  
  5. $tmpl = new  Template('template/news.tpl');
  6.  
  7.        $zapytanie    = 'SELECT * FROM news where id='.NR.'';
  8.        $wykonaj    = mysql_query         ($zapytanie);
  9. while(    $wiersz        = mysql_fetch_array ($wykonaj)){
  10.            
  11.    $news = Array(
  12.        'tytul'          => $wiersz['tytul'],
  13.        'news'         => $wiersz['text'],
  14.        'data'        => $wiersz['data'],
  15.        'dodal'        => $wiersz['dodal']
  16.        );                
  17.    }
  18.      
  19. $tmpl->add($news);
  20. echo $tmpl->execute();
  21. ?>


news.tpl
  1. <tr>
  2. <td>{tytul}<br /></td>
  3. </tr>
  4. <tr>
  5. <td>{news}<br /></td>
  6. </tr>
  7. <tr>
  8. <td>{data} : {dodal}</td>
  9. </tr>
  10. <br /><br />


template.inc.php

  1. <?php
  2. class Template {
  3.    var $tmpl;
  4.    var $dane;
  5.    var $jezyk;
  6.  
  7.    function Template ($name)
  8.    {
  9.        $this->tmpl = implode('', file($name));
  10.        $this->dane = Array();
  11.    }
  12.  
  13.    function add($name, $value = '')
  14.    {
  15.        if (is_array($name)) {
  16.            $this->dane = array_merge($this->dane, $name);
  17.        } else if (!empty($value)) {
  18.            $this->dane[$name] = $value;
  19.        }
  20.    }
  21.  
  22.    function execute() {
  23.        return preg_replace('/{([^}]+)}/e', '$this->dane["1"]',
  24.                $this->tmpl);
  25.    }
  26.  
  27. }
  28. ?>



  1. CREATE TABLE `news` (
  2. `id` text NOT NULL,
  3. `tytul` text NOT NULL,
  4. `text` text NOT NULL,
  5. `data` date NOT NULL DEFAULT '0000-00-00',
  6. `dodal` text NOT NULL,
  7. `jezyk` text NOT NULL
  8. ) TYPE=MyISAM;
  9.  
  10. --
  11. -- Zrzut danych tabeli `news`
  12. --
  13.  
  14. INSERT INTO `news` VALUES ('1', 'News 1', 'to jest news news 1', '0000-00-00', 'Jacek', 'pl');
  15. INSERT INTO `news` VALUES ('1', 'News 2', 'to jest tekst news 2', '0000-00-00', 'Darek', 'pl');