Greg Brown - 2004-07-08

Logged In: YES
user_id=629601

Hi there... I've done this and it is amazingly simple. Look
at the rssFeed.php file I've pasted into the end of this
message. You'll have to replace the relevant text (eg
<USER>, <PASSWORD> etc) with your particulars...

Once you have the rssFeed.php uploaded to your server, test
it with this Validator website (very useful!!!!)
http://feedvalidator.org/

Good luck!
Greg

PS I have my top 10 list amongst other things displayed in a
postnuke powered intranet portal. Looks very slick...

++++++++++++
CODE
++++++++++++

<?
// Based on information sourced at
//
http://www.cadenhead.org/workbench/stories/2004/05/22/publish-mysql-data-in-rss.html

/**********************************************************************************
* rss.php
* Version: 1.00
* Author: Rogers Cadenhead
* Date: 05/21/2004
* http://www.cadenhead.org/workbench/
*
**********************************************************************************
This program is distributed in the hope that it will be
useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This work is hereby released into the Public Domain. To
view a copy of the public
domain dedication, visit
http://creativecommons.org/licenses/publicdomain/ or
send a letter to Creative Commons, 559 Nathan Abbott Way,
Stanford, California
94305, USA.
**********************************************************************************/

// prepare HTML text for use as UTF-8 character data in XML
function cleanText($intext) {
return utf8_encode(
htmlspecialchars(
stripslashes($intext)));
}

// set the file's content type and character set
// this must be called before any output
header("Content-Type: text/xml;charset=utf-8");

// retrieve database records
$db = mysql_pconnect("localhost", "<USERNAME>", "<PASSWORD>");

if (!$db)
{
error_log("Error: Could not connect to database :(");
exit;
}

// store items from the database in the $result1 array
mysql_select_db("<DATABASE NAME>");

$query1 = "select bug_id, title from phpbt_bug order by
bug_id desc limit 5";
$result1 = mysql_query($query1);
$phpversion = phpversion();

// display RSS 2.0 channel information

ECHO <<<END
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>WebRFE RSS FEED</title>
<link>http://www.my.server.com</link>
<description>Displays the 5 most recent bugs</description>
<language>en-us</language>
<docs>http://backend.userland.com/rss</docs>
<generator>PHP/$phpversion</generator>
END;

// loop through the array pulling database fields for each item
for ($i = 0; $i < mysql_num_rows($result1); $i++) {
@$row = mysql_fetch_array($result1);
$bug_id = "Bug# ".cleanText($row["bug_id"]);
$bug_link =
"http://www.my.server.com/phpbt-0.9.0/bug.php?op=show&amp;bugid=".$row["bug_id"];
$bug_title = cleanText($row["title"]);

// display an item
ECHO <<<END

<item>
<title>$bug_id</title>
<description>$bug_title</description>
<link>$bug_link</link>
</item>
END;

}

ECHO <<<END

</channel>
</rss>
END;
?>