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
-k1ilo-
post
Post #2





Goście







  1. <?php
  2. public function wyswietl($ile) {
  3. $query = 'SELECT id, tytul, tresc, data FROM news ORDER BY id DESC LIMIT 0, '.$ile.'';
  4. $this->Baza = mysql_query($query);
  5. $aNews = array();
  6. * while($r = mysql_fetch_array($query)) {
  7. $aNews[] = $r;
  8. }
  9. print_r ($aNews);
  10. return $aNews;
  11. }
  12. ?>

nadal Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource news.php

linia z * wskazana jest przez parser
chciałem sprawdzić czy ta tablica naprawdę nic nie zawiera wiec zrobiłem
print_r ($aNews);
i dostaje tylko Array();
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: 31.12.2025 - 14:41