Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][MYSQL][Smarty] niewyświetla
-k1ilo-
post
Post #1





Goście







Witam mam problem mam klasę
  1. <?php
  2. class news
  3. {
  4. private $Baza;
  5. public function __construct() {
  6. $this->Baza = mysql_connect("localhost", "user", "pass")
  7. or die('connect_error'.mysql_error());
  8. mysql_select_db('dbname')or die('database_error'.mysql_error());
  9. }
  10.  
  11. public function wyswietl($ile) {
  12. $query = 'SELECT id, tytul, tresc, data FROM news ORDER BY id DESC LIMIT 0, "'.$ile.'"';
  13. mysql_query($query);
  14. $aNews = array();
  15. while($r = mysql_fetch_array($query)) {
  16. $aNews[] = $r;
  17. }
  18. return $aNews;
  19. }
  20. }
  21. ?>

i teraz nie potrafię wyświetlić wyników
  1. <?php
  2. require './news.php';
  3.  
  4. $smarty = new blog;
  5.  
  6. $a = new news;
  7. $a -> wyswietl(1);
  8.  
  9. $smarty -> assign('news', $a -> wyswietl());
  10. $smarty -> display('news.tpl');
  11. ?>


Pewnie coś źle robię tylko nie mam już pomysłu co.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 561
Pomógł: 6315
Dołączył: 27.12.2004




@Shili to podajmy juz caly kod bo po naszych odpowiedziach sie zamota (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)

  1. <?php
  2. public function wyswietl($ile) {
  3. $query = 'SELECT id, tytul, tresc, data FROM news ORDER BY id DESC LIMIT '.$ile;
  4. $res = mysql_query($query) or die('Zapytanie: '.$query.' --- błąd: '.mysql_error());
  5. $aNews = array();
  6. while($r = mysql_fetch_array($res)) {
  7. $aNews[] = $r;
  8. }
  9. print_r ($aNews);
  10. return $aNews;
  11. }
  12. ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 29.12.2025 - 22:21