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





Grupa: Zarejestrowani
Postów: 1 085
Pomógł: 231
Dołączył: 12.05.2008

Ostrzeżenie: (0%)
-----


Oczywiście, ja w takim razie jeszcze pozwolę sobie na drobną optymalizację (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif)
  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($aNews[] = mysql_fetch_array($res));
  7. print_r ($aNews);
  8. return $aNews;
  9. }
  10. ?>


Ten post edytował Shili 14.08.2008, 10:45: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: 30.12.2025 - 05:13