Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [SMARTY] Pobieranie danych z bazy
maxmer
post
Post #1





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 25.03.2007

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


Nie wiem co jest nie tak pobieram dane z bazy ale treść itd. są w jednej linijce jak zrobić by każdy news był w nowej linii?

index.php
  1. <?
  2. require('db_connect.php');
  3. require('./smart/Smarty.class.php');
  4.  
  5.  $tpl = new Smarty;
  6. $tpl -> template_dir = './templates/';
  7. $tpl -> compile_dir = './templates_c/';
  8.  
  9.  
  10. $tablica = array();  
  11. $Query='SELECT * FROM news'; 
  12. $result = mysql_query($Query) or die(mysql_error());
  13. while($a = mysql_fetch_array($result)) 
  14. {
  15.  
  16. $tablica[] = $a;
  17.  
  18. }
  19. $tpl -> assign('news', $tablica);  
  20. $tpl -> display('lcms/index.tpl');
  21. ?>



index.tpl

  1. <table width="100%">
  2. <tr>
  3. <td>{section name=a loop=$news} {$news[a].name} {/section}</td>
  4. </tr>
  5. <tr>
  6. <td>{section name=a loop=$news} {$news[a].txt} {/section}</td>
  7. </tr>
  8. <tr>
  9. <td>{section name=a loop=$news} {$news[a].data} {/section}</td>
  10. <td>{section name=a loop=$news} {$news[a].autor} {/section}</td>
  11. </tr>
Go to the top of the page
+Quote Post
rojmarek
post
Post #2





Grupa: Zarejestrowani
Postów: 85
Pomógł: 0
Dołączył: 10.09.2005

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


Cytat(maxmer @ 11.05.2007, 19:40:58 ) *
  1. <td>{section name=a loop=$news} {$news[a].name} {/section}</td>

to przeanalizuj co ta linijka zrobi...? przeleci przez wszystkie newsy i wyswietli name tego newsa...
po prostu wszystko w jeden section musisz wrzucic i bedzie ok (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)

  1. <table width="100%">
  2. <tr>
  3. <td>{section name=a loop=$news} {$news[a].name}</td>
  4. </tr>
  5. <tr>
  6. <td>{$news[a].txt}</td>
  7. </tr>
  8. <tr>
  9. <td>{$news[a].data}</td>
  10. <td>{$news[a].autor} {/section}</td>
  11. </tr>
Go to the top of the page
+Quote Post

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: 19.09.2025 - 02:58