j'ai trouvé un tuto qui doit être ce que je cherche mais j'ai besoin de deux éclaircisements.
Le tuto :
Dynamic RSS Feed
Interested in putting an RSS Feed like the one I have on my site on your site? If your site runs PHP and mySQL, this is the tutorial for you. It will take you through the steps to pull out the data and have it working in no time.
Ok, first thing you want to do is make a file. I called mine rss.php, but you can call it whatever you want (but make sure the file extention is PHP!)
Now we're going to throw some code into the page to get it started.
<?php
header ("Content-type: text/xml");
echo ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
?>
<rss version='2.0'>
<channel>
<title>Your Title Here</title>
<description>Your description Goes Here.</description>
<link>http://linktoyour/rss.php</link>
<language>en-us</language>
This is the top code in your document. You'll want to change the title, description and link to fit your needs. Next, we're going to connect to the database.
<?php
$db_host = "localhost";
$db_name = ""; //database name
$db_user = ""; //database user
$db_pass = ""; //user password
$db_connection = @mysql_pconnect($db_host,$db_user,$db_pass) or die("Sorry, cannot connect to database.");
@mysql_select_db($db_name,$db_connection) or die(dbdown());
Put this under the section you've already put in. Make sure you put in the appropriate connection information. Also, you could replace this with an include of your connection script if you prefer. I'm just doing this in one file for the sake of simplicity. Ok, after you've done that, we're going to put in the code that does the query and puts the entries into the RSS file.
$result = mysql_query ("SELECT * FROM `%%TABLE%%` ORDER BY `id` DESC LIMIT 0,10 ") or die (mysql_error());
while ($row = mysql_fetch_array ($result)) {
$desc = $row[2];
$desc = str_replace("\n","<br />",$desc);
echo (" <item>
<title>");
echo $row[1];
echo ("</title>
<description>");
echo $desc; //content you want the person to read
echo ("</description>
<link>http://yoursite.com/index.php?article=");
echo $row[0];
echo ("</link>
</item>\n\n");
}
With this, you'll want to edit a couple things. First, in the query, you'll want to change %%TABLE%% to the table you're selecting from. You can also change the query to specify certain fields that will be used and also change the number it outputs. Next is the $row[] array numbers. You'll want them to reflect your own site. In my case, 0 is the id, 1 is the title and 2 is the actual article. And finally, you'll want to replace the link to your own site. On that note, you'll want to set it up so that it goes to the version on your site. And now for the final piece of the code.
C'est ce que je ne comprends pas. Qu'est-ce qu'une table ? Je la trouve où ?
Quest-ce que le "$row[] array numbers"
mysql_free_result ($result);
?>
</channel>
</rss>
Nothing to change this time. Just save it, and try viewing it in your RSS reader.
Finally, once you're done that, you should add something to your index so that web browsers can be aware you have a RSS feed on your site.
<link rel="alternate" type="application/rss+xml" title="Title of RSS feed" href="http://yoursite/rss.php" />
Just change the title and href values and put it inside the head tags on your header.
Merci,
Arnob
© 2005 Mike Haugland - Version 2
Privacy Policy Terms of se