[XML] Flux rss base de donnée quelque soucis
Bonjour je n'arrive pas à écrire mon flux rss dans mon fichier voici ce que j'ai fait suivant des exemple de la toile
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| <?php
include("sources/config.php"); // Fichier de configuration
function datefr($date)
{
$date = explode('-', $date);
$date = array_reverse($date);
$date = implode('/', $date);
return $date;
}
$fichier = "flux.rss"; // Nom du fichier RSS à créer
// Création du flux RSS
$flux= "<?xml version='1.0' encoding='ISO-8859-1'?>\n";
$flux.= "<rss version='2.0'>\n";
$flux.= " <channel> \n";
$flux.= " <title>".$titre."</title>\n";
$flux.= " <link>".$lien_titre."</link>\n";
$flux.= " <description>".$description."</description> \n";
$req = "SELECT * FROM annonce ORDER BY date DESC LIMIT 0, $limit";
$rep = mysql_query($req) or die (mysql_error());
//////// PARTIE A MODIFIER /////////
// Mettez ici les noms des champs de votre requête à utiliser pour les balises (titre, id (lien), description, date)
while($row = mysql_fetch_assoc($rep)) {
$flux.= " <item>\n";
$flux.= " <title>".$row['typb']."</title>\n"; // Titre
$flux.= " <link>".$base_lien.$row['idA']."</link>\n"; // Lien associé
$flux.= " <guid isPermaLink='false'>".$row['idA']."</guid>\n";
$flux.= " <description>".$row['description']."</description>\n"; // Description
$flux.= " <pubDate>".datefr($row['date'])." GMT</pubDate>\n"; // Date de publication
$flux.= " </item>\n";
}
$flux.= " </channel>\n";
$flux.= "</rss>\n";
// écriture dans le fichier
$fp = fopen("flux.xml", 'w+');
fputs($fp, $flux);
fclose($fp);
mysql_close()
?> |
fichier écriture
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| <?xml version="1.0" encoding="utf-8"?>
<rss version='2.0'>
<channel>
<title>H-immo</title>
<link>http://www.h-immo.be</link>
<description>Les dernières Annonces immobiliere H-immo.be</description>
<item>
<title> </title>
<link> </link>
<description> </description>
<pubDate> </pubDate>
</item>
</channel>
</rss> |