Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php] Problem z rss
Forum PHP.pl > Forum > Przedszkole
skorumpowany
hej,

mam problem z wyświetlaniem rekordów z bazy w rssie, mialem dac do klasy pętle while itd. no dalem tak jak myslalem ze to trzeba zrobic jednakze nie dziala sad.gif

pomoze ktos?

oto kodzik:

@ patrzcie komentarze winksmiley.jpg

  1. <?php
  2. require_once('rss1.php5');
  3.  
  4. $rss = new RssGenerator();
  5.  
  6. $rss->setPubDate('Tue, 20 Feb 2007 21:49:50 GMT');
  7. $rss->setLanguage('pl-pl');
  8. $rss->setCopyright('skorumpowany');
  9.  
  10. $rss->generateRssChannel('Kanał rss', 'http://www.skorumpowany.pl', 'Kanał RSS serwisu skorumpowany.pl');
  11.  
  12.  
  13.  
  14.  //funkcyjka laczaca sie z baza 
  15.  
  16.  
  17.  function baza_pol()
  18.  {
  19.  
  20. //$db = mysql_connect("xxx", "xxx", "xxx");
  21. $db = mysql_connect("localhost", "xxxr", "xxxj");
  22. mysql_query("set names latin2;");
  23. if (!$db)
  24.  {
  25. echo "<b>NIE MA POLACZENIA Z BAZA DANYCH</b>";
  26.  }
  27.  
  28. /
  29. if (!$db)
  30.  {
  31. echo "<b>BRAK POLACZENIA Z BAZA DANYCH</b>";
  32.  }
  33.  
  34.  }
  35.  
  36. define ('baza_pol',0);
  37. include 'includes/pnAPI.php';
  38.  
  39.  
  40. baza_pol();
  41. $query1 = mysql_query("SELECT * FROM wiadomosci ORDER BY id DESC");  
  42.  
  43. // robie petle tak jak kazal autor
  44.  
  45.  while ($rekord=mysql_fetch_assoc($query1))
  46. {
  47.  
  48. $id = $rekord['id'];
  49. $zajawka = $rekord['opis'];
  50. $autor = $rekord['autor'];
  51. $kategoria = $rekord['id_kat'];
  52. if($kategoria == '1') {
  53. $nazwa_kat = 'Motoryzacja';
  54. } elseif ($kategoria == '2') {
  55. $nazwa_kat = 'Motoryzacja2';
  56. } elseif ($kategoria == '3') {
  57. $nazwa_kat = 'Motoryzacja4';
  58. } elseif ($kategoria == '4') {
  59. $nazwa_kat = 'Motoryzacja5';
  60. } elseif ($kategoria == '5') {
  61. $nazwa_kat = 'Motoryzacja0';
  62. }
  63.  
  64.  
  65. //$opis = stripslashes (htmlspecialchars ($rekord['opis']));
  66. //$opis = htmlspecialchars($rekord['opis']);
  67. $tytul = $rekord['tytul'];
  68. $link = pnVarPrepForDisplay(pnGetBaseURL() . "modules.php?op=modload&name=wiadomosci&cmd=read&id=$id");
  69. $opis = pnVarPrepForDisplay(strip_tags($zajawka));
  70.  
  71. // tu koniec petli ale...
  72.  
  73. }  
  74.  
  75. // ...tu mi wyswietla tylko jeden rekord, jak klamre zamkne dalej czyli po tamtej 
    tablicy na dole o wyswietla mi ze DOM nie moze tworzyc wiecej obiektów :(
  76.  
  77.  
  78.  
  79. $rss->generateRssItem(''.$tytul.'', ''.$link.'', ''.$opis.'');
  80.  
  81. //$rss->generateRssItem('Title2', 'link2', 'afasfasff');
  82.  //$rss->generateRssItem('Title3', 'link2', 'afasfasff');
  83.  // $rss->generateRssItem('Title4', 'link2', 'afasfasff');
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90. echo $feed;
  91.  
  92. }
  93.  
  94. ?>


plik z klasą:

  1. <?php
  2. class RssGenerator {
  3.  
  4. private $channelElement = array();
  5. private $itemElement = array();
  6. private $dom;
  7. private $channel;
  8.  
  9. function __construct() {
  10.  
  11. }
  12.  
  13. function setLanguage($value) {
  14.  
  15.  $this->ChannelElement[language] = $value ;
  16.  
  17. }
  18.  
  19. function setCopyright($value) {
  20.  
  21. $this->ChannelElement[copyright] = $value;
  22.  
  23. }
  24.  
  25. function setPubDate($value) {
  26. if(empty($value)) {
  27.  
  28. $this->ChannelElement[pubdate] = date(r);
  29.  
  30. }else {
  31.  
  32. $this->ChannelElement[pubdate] = $value;
  33.  
  34. }
  35.  
  36. }
  37.  
  38. /**
  39.  * generateRssChannel()
  40.  * Funkcja generująca <channel>.
  41.  *
  42.  * @param $title - Tytul strumienia.
  43.  * @param $link - Adres url do strony "własciciela" strumienia.
  44.  * @param $description - Opis strumienia.
  45.  * 
  46.  */
  47.  
  48. function generateRssChannel($title, $link, $description) {
  49.  
  50. $this->channelElement[title] = $title; 
  51. $this->channelElement[link] = $link; 
  52. $this->channelElement[description] = $description; 
  53.  
  54. $this->dom = new DOMDocument('1.0', 'utf-8');
  55.  
  56. $mainNode = $this->dom->appendChild($this->dom->createElement('rss'));
  57. $mainNode->setAttribute('version', '2.0');
  58.  
  59. $this->channel = $mainNode->appendChild($this->dom->createElement('channel'));
  60.  
  61. /*<channel>*/
  62.  
  63. /* Wymagane elementy */
  64.  
  65. $this->channel->appendChild($this->dom->createElement('title', $this->channelElement[title]));
  66. $this->channel->appendChild($this->dom->createElement('link', $this->channelElement[link]));
  67. $this->channel->appendChild($this->dom->createElement('description', $this->channelElement[description]));
  68.  
  69. /* Opcjonalne elementy */
  70.  
  71. if(!empty($this->channelElement[language])){ 
  72. $this->channel->appendChild($this->dom->createElement('language', $this->channelElement[language]));
  73. }
  74. if(!empty($this->channelElement[copyright])){ 
  75. $this->channel->appendChild($this->dom->createElement('copyright', $this->channelElement[copyright])); 
  76. }
  77. if(!empty($this->channelElement[pubdate])){ 
  78. $this->channel->appendChild($this->dom->createElement('pubdate', $this->channelElement[pubdate])); 
  79. }
  80.  
  81.  
  82.  
  83. }
  84.  
  85. /**
  86.  * generateRssItem()
  87.  * Funkcja generująca <item>.
  88.  *
  89.  * @param $title - Tytul strumienia.
  90.  * @param $link - Adres url itemu.
  91.  * @param $description - Opis strumienia.
  92.  * 
  93.  */
  94.  
  95. function generateRssItem($title, $link, $description) {
  96.  
  97. $this->itemElement['title'] = $title; 
  98. $this->itemElement['link'] = $link; 
  99. $this->itemElement['description'] = $description; 
  100.  
  101. $item = $this->channel->appendChild($this->dom->createElement('item'));
  102. $item->appendChild($this->dom->createElement('title', $this->itemElement[title]));
  103. $item->appendChild($this->dom->createElement('link', $this->itemElement[link]));
  104. $item->appendChild($this->dom->createElement('description', $this->itemElement[description]));
  105.  
  106. }
  107.  
  108. function getRss() {
  109.  
  110. $this->dom->formatOutput = true;
  111.  
  112. return $this->dom->saveXML();
  113.  
  114.  
  115. }
  116.  
  117.  
  118. }
  119. ?>


moja znajomosc php jest na prawde nie duza, prosze o pomoc smile.gif
siemakuba
A czy mógłbyś napisać co konkretnie nie działa? Jak te niedziałanie się objawia? Wyświetla się jakiś błąd?
Przy tak skąpym, a właściwie braku opisu problemu i takiej ilości kodu ciężko coś powiedzieć.

pozdr.
skorumpowany
to cały kod, problem to nie wyświetlanie wszystkich rekordów tylko jednego, nie umiem stworzyć pętli while sad.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.