Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php/smarty]Problem z "pętlą"
zlw
post
Post #1





Grupa: Zarejestrowani
Postów: 44
Pomógł: 0
Dołączył: 30.04.2007
Skąd: WWA

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


Mam pewien problem. Chcę wyświetlić na stronie głównej newsy pobrane z bazy.

Tak więc kod PHP wygląda tak:

  1. <?php
  2. $result = mysql_query("SELECT news_num FROM cms_config")
  3. or die("Niepoprawne zapytanie MySQL");
  4. $news_num = mysql_fetch_array($result);
  5.  
  6. $result = mysql_query("SELECT title,author, date, news_id, body_short, body_long FROM cms_news ORD
    ER BY date DESC"
    )
  7. or die("Niepoprawne zapytanie MySQL");
  8. $number = mysql_num_rows($result);
  9.  
  10.  
  11.  
  12. if ($number > $news_num[news_num] )
  13. {
  14. $liczba_news = $news_num[news_num];
  15. }
  16. else
  17. {
  18. $liczba_news = $number;
  19. }
  20.  while ($n <> $liczba_news )
  21. {
  22.  
  23. $news = mysql_fetch_array($result);
  24. $n = $n + 1;
  25. $data = date('d.m.Y H:i', strtotime($news[date]));
  26.  
  27. $smarty->assign('news_number',$liczba_news);
  28. $smarty->assign('news_title',$news[title]);
  29. $smarty->assign('news_short',$news[body_short]);
  30. $smarty->assign('news_author',$news[author]);
  31. $smarty->assign('news_id',$news[news_id]);
  32. $smarty->assign('news_date',$data);
  33. $smarty->assign('news_long',$news[body_long]);
  34. ?>



Kod "smarków":

  1. {section name=customer loop=$news_number}
  2. <table border=0>
  3. <tr>
  4. <td width=140 id=title><b><font size=2 face=Arial>{$news_title}</font></b><hr></td>
  5. </tr>
  6. <tr>
  7. <td height=55 width=280 valign=top>{$news_short}</td></tr>
  8. <tr>
  9. <td font><b>Autor:</b> {$news_author}<br><b>Data:</b> {$news_date}</td>
  10. </tr>
  11. {if $news_long <> ""}
  12. <tr><td><a href=?news_id={$news_id}>Czytaj więcej</a></td></tr>
  13. {/if}
  14. <br><br>
  15. </font>
  16. {/section}


Efekt jest taki, że wyświetla co prawda dobrą liczbę news'ów, ale są to te same newsy.
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: 23.08.2025 - 05:06