Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
<?php
header("Content-Type: application/xml; charset=iso-8859-1");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ". gmdate("D, d M Y H:i:s") ." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
echo '<' . '?xml version="1.0" encoding="ISO-8859-1" ?' . '>';
?>
<rss version="2.0">
<channel>
<title>Gazeta da Paraiba Feed RSS</title>
<link>http://www.gazetadaparaiba.com.br</link>
<description>Gazeta da Paraiba, Seu Portal de Noticias</description>
<language>pt-br</language>
<webMaster>luan_radical@hotmail.com</webMaster>
<?
$conexao = mysql_connect("localhost", "usuario", "senha");
$db = mysql_select_db("meu BD");
$sql = "SELECT * FROM s_noticias ORDER BY data DESC LIMIT 10";
$resultado = mysql_query($sql)
or die (mysql_error());
while ($linha=mysql_fetch_array($resultado)) {
$id = $linha["id"];
$titulo = $linha["titulo"];
echo "<item>";
echo "<title>$titulo</title>";
echo "<link>http://www.gazetadaparaiba.com.br/?p=noticia&id=$id</link>";
echo "<description>$titulo ...</description>";
echo "</item>";
}
?>
</channel>
</rss>Mude o limite de seu SQL para 1:
Ao invés de:
$sql = "SELECT * FROM s_noticias ORDER BY data DESC LIMIT 10";
Coloque:
$sql = "SELECT * FROM s_noticias ORDER BY data DESC LIMIT 1";
E poste aqui a fonte RSS.
>
Aparentemente não falta nada.
O que está acontecendo que faz você dizer que não funciona? Qual o ocorrido?
Bom amigo eu coloco ele mais não mostra nada http://gazetadaparaiba.com.br/feed.php mais se eu clicar em Exbir codigo de fonte ele mostra o Codigo e com as noticias todas do Banco de Dados só não faz mostrar na pagina mesmo. O que será que ta acontecendo?
Abraços
Faça o seguinte:
Coloque a flag CDATA em todas as tags:
<tag><![CDATA[ Conteúdo ]]></tag>
Depois tente validar no seguinte endereço:
>
Faça o seguinte:
Coloque a flag CDATA em todas as tags:
<tag><![CDATA[ Conteúdo ]]></tag>
Depois tente validar no seguinte endereço:
Amigo como eu faço isso você tem algum exemplo pra colocar essa <tag><![CDATA[ Conteúdo ]]></tag>?
Abraços
<?php
/**
* Nova instancia de DOMDocument
* Versão 1.0, Codificação UTF-8
*/
$DOMDocument = new DOMDocument( '1.0', 'utf-8' );
/**
* Formata o Output para uma boa identação nas tags
*/
$DOMDocument->formatOutput = true;
/**
* Nova instancia de PDO
*/
$PDO = new PDO( 'mysql:host=localhost;dbname=seu db', 'root', 'sua senha' );
$PDO->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$PDO->setAttribute( PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC );
$PDO->setAttribute( PDO::ATTR_TIMEOUT, 5 );
$RSS = $DOMDocument->createElement( 'rss' );
$RSS->setAttribute( 'version', '2.0' );
$DOMDocument->appendChild( $RSS );
$Channel = $DOMDocument->appendChild( $DOMDocument->createElement( 'channel' ) );
$Channel->appendChild( $DOMDocument->createElement( 'title', 'Gazeta da Paraiba Feed RSS' ) );
$Channel->appendChild( $DOMDocument->createElement( 'link', 'http://www.gazetadaparaiba.com.br' ));
$Channel->appendChild( $DOMDocument->createElement( 'description', 'Gazeta da Paraiba, Seu Portal de Noticias' ));
$Channel->appendChild( $DOMDocument->createElement( 'language', 'pt-Br' ));
$Channel->appendChild( $DOMDocument->createElement( 'webMaster', 'luan_radical@hotmail.com' ));
$Query = $PDO->query( "SELECT * FROM `s_noticias` ORDER BY `data` DESC LIMIT 10" );
foreach( $Query->fetchAll( PDO::FETCH_ASSOC ) as $Data ){
$Item = $Channel->appendChild( $DOMDocument->createElement( 'item' ) );
$Item->appendChild( $DOMDocument->createElement( 'title', $Data['titulo'] ) );
$Item->appendChild( $DOMDocument->createElement( 'link', htmlentities('http://www.gazetadaparaiba.com.br/?p=noticia&id='.$Data['id']) ));
$Item->appendChild( $DOMDocument->createElement( 'description', $Data['titulo'] ));
}
/**
* Mostra o Ouput
*/
echo $DOMDocument->saveXML();
Provavelmente o Ouput vai sair no Source ..
C:\Users\Andrey>cd ..
C:\Users>cd ..
C:\>cd \dev\mysql\bin\
C:\dev\mysql\bin>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.41 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database rss;
Query OK, 1 row affected (0.02 sec)
mysql> use rss;
Database changed
mysql> create table noticias(
-> id int( 11 ) not null auto_increment,
-> titulo varchar( 42 ) not null,
-> noticia text not null,
-> primary key ( `id` )
-> )Engine = MyISAM;mysql> insert into noticias values( null, 'Uma Noticia', 'Primeira Notica, Testando RSS' );
Query OK, 1 row affected (0.00 sec)
mysql> select * from noticias;
+----+-------------+-------------------------------+
| id | titulo | noticia |
+----+-------------+-------------------------------+
| 1 | Uma Noticia | Primeira Notica, Testando RSS |
+----+-------------+-------------------------------+
1 row in set (0.00 sec)
mysql>
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"/>
<channel>
<title>Gazeta da Paraiba Feed RSS</title>
<link>http://www.gazetadaparaiba.com.br</link>
<description>Gazeta da Paraiba, Seu Portal de Noticias</description>
<language>pt-Br</language>
<webMaster>luan_radical@hotmail.com</webMaster>
<item>
<title>Uma Noticia</title>
<link>http://www.gazetadaparaiba.com.br/?p=noticia&id=1</link>
<description>Primeira Notica, Testando RSS</description>
</item>
</channel>
Aparentemente não falta nada.
O que está acontecendo que faz você dizer que não funciona? Qual o ocorrido?