Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [HTML][MySQL][PHP]Smarty
lol99
post 31.10.2010, 12:12:31
Post #1





Grupa: Zarejestrowani
Postów: 75
Pomógł: 0
Dołączył: 25.12.2008

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


witam
dlaczego wyświetla mi tylko ostatni wpis?
jak poprawnie użyć pętli while w smarty?
  1. <?php
  2. include_once('smarty/Smarty.class.php');
  3. $smarty= new Smarty();
  4. $smarty->template_dir = 'template/';
  5. $smarty->compile_dir = 'template_c/';
  6.  
  7.  
  8.  
  9. include 'config.php';
  10. @mysql_connect($mysql_host, $mysql_user, $mysql_pass);
  11. @mysql_select_db($mysql_db);
  12. @mysql_query('SET CHARSET utf8');
  13. $zapytanie = "SELECT `text` FROM `tips`";
  14. $idzapytania = mysql_query($zapytanie);
  15. while ($wiersz = mysql_fetch_row($idzapytania))
  16. {
  17. $smarty->assign('name',$wiersz[0]);
  18.  
  19. }
  20.  
  21.  
  22.  
  23.  
  24.  
  25. $smarty->display('index.tpl');
  26. ?>

Go to the top of the page
+Quote Post
ADeM
post 31.10.2010, 12:41:31
Post #2





Grupa: Zarejestrowani
Postów: 455
Pomógł: 69
Dołączył: 23.10.2004
Skąd: Oświęcim

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


W pętli nadpisujesz ciągle zmienną "name".
Spróbuj zrobić tak:
  1. <?php
  2. include_once('smarty/Smarty.class.php');
  3. $smarty= new Smarty();
  4. $smarty->template_dir = 'template/';
  5. $smarty->compile_dir = 'template_c/';
  6.  
  7.  
  8.  
  9. include 'config.php';
  10. @mysql_connect($mysql_host, $mysql_user, $mysql_pass);
  11. @mysql_select_db($mysql_db);
  12. @mysql_query('SET CHARSET utf8');
  13. $zapytanie = "SELECT `text` FROM `tips`";
  14. $idzapytania = mysql_query($zapytanie);
  15.  
  16. $tmp = array();
  17. while ($wiersz = mysql_fetch_row($idzapytania))
  18. {
  19. $tmp[] = $wiersz[ 0 ];
  20. }
  21. $smarty->assign( 'name' , $tmp );
  22.  
  23.  
  24.  
  25.  
  26.  
  27. $smarty->display('index.tpl');
  28. ?>

A później w szablonie użyj pętli na tablicy "name".


--------------------
Go to the top of the page
+Quote Post
lol99
post 31.10.2010, 18:32:25
Post #3





Grupa: Zarejestrowani
Postów: 75
Pomógł: 0
Dołączył: 25.12.2008

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


mogę prosić przykład, bo za bardzo nie wiem jak wyglądają pętle w smarty.
Go to the top of the page
+Quote Post
CuteOne
post 31.10.2010, 18:51:55
Post #4





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

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


petle
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: 25.07.2025 - 11:05