Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Smarty]Problem z Newsami
Misiek92
post 26.12.2009, 13:35:27
Post #1





Grupa: Zarejestrowani
Postów: 24
Pomógł: 1
Dołączył: 19.07.2009
Skąd: Kraków

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


Witam.

Mam mały problem ze smartami dokładniej z wyświetlaniem, w bazie mam mam 1 wpis z newsem, na stronie wyświetla mi tego newsa + 1 pustego


  1. $news = array();
  2. if(mysql_num_rows($query)) while($news[] = mysql_fetch_assoc($query)){}
  3. $smarty->assign('news', $news);



  1. {foreach name=news from=$news item=item}
  2. <tr><td>Tytuł: {$item.topic}<tr/><td/>
  3. <tr><td>Data: {$item.data}<tr/><td/>
  4. <tr><td>Autor: {$item.author|default:"Brak autora"}<tr/><td/>
  5. <tr><td>Tekst: {$item.text}<tr/><td/>
  6. {/foreach}


W wyniku dostaje

Cytat
Tytuł: dfasdfas
Data: 2009-12-26 02:12
Autor: fasdfasdfasd
Tekst: safsafasfd

Tytuł:
Data:
Autor: Brak autora
Tekst:


Ma może ktoś pomysł w czym może siedzieć problem?
Go to the top of the page
+Quote Post
Matte
post 26.12.2009, 14:18:22
Post #2





Grupa: Zarejestrowani
Postów: 35
Pomógł: 7
Dołączył: 4.04.2009
Skąd: Sosnowiec

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


Do kodu php dopisz var_dump($news). Prawdopoodbnie cosik zlego dzieje Ci sie z tablica.
Go to the top of the page
+Quote Post
Misiek92
post 26.12.2009, 14:27:46
Post #3





Grupa: Zarejestrowani
Postów: 24
Pomógł: 1
Dołączył: 19.07.2009
Skąd: Kraków

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


Wynik
Cytat
array(2) { [0]=> array(6) { ["id"]=> string(2) "16" ["data"]=> string(16) "2009-12-26 02:12" ["topic"]=> string(8) "dfasdfas" ["text"]=> string(10) "safsafasfd" ["author"]=> string(12) "fasdfasdfasd" ["hide"]=> string(1) "0" } [1]=> bool(false) }
Go to the top of the page
+Quote Post
cim
post 26.12.2009, 14:39:05
Post #4





Grupa: Zarejestrowani
Postów: 208
Pomógł: 28
Dołączył: 9.08.2004
Skąd: Stargard

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


Witam,

ogółem o jeden wpis za dużo (mysql_fetch_assoc zwraca false, bo nie ma więcej rekordów, ale ten false jest już automatem dodawany do tablicy z rekordami):
Kod
[1]=> bool(false)


Może spróbuj tak:
  1. if(mysql_num_rows($query)) while($rekord = mysql_fetch_assoc($query)){ $news[] = $rekord}


Pozdrawiam


--------------------
errare humanum est
Go to the top of the page
+Quote Post
Misiek92
post 26.12.2009, 14:54:55
Post #5





Grupa: Zarejestrowani
Postów: 24
Pomógł: 1
Dołączył: 19.07.2009
Skąd: Kraków

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


Dzięki wielkie, leci pomógł.

Wrazie czego jakby ktoś miał podobny problem zamieszczam kod smile.gif


  1. if(mysql_num_rows($query))
  2. {
  3. while($rekord = mysql_fetch_assoc($query))
  4. {
  5. $news[] = $rekord;
  6. }
  7.  
  8. }
  9. $smarty->assign('news', $news);
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 19.07.2025 - 19:21