php rss

How would I create an rss that is generated by php and uses db values?
Who is Participating?
this is my own real life code. just replace my tables by your tables in your context!
specification of the xml can be found here


/* connection to the database and standard function */

/* Select on system table */
$querySystem = "select * from system where company = $company";
$resultSystem = mysql_query($querySystem);
$numberSystem = mysql_numrows($resultSystem);
$webSiteName = htmlspecialchars(mysql_result($resultSystem,0,"websitename"), ENT_QUOTES);
$mainLanguage = mysql_result($resultSystem,0,"mainlanguage");
$adminEmail = mysql_result($resultSystem,0,"adminEmail");
if ($language == "") {
   $language = $mainLanguage;

$queryMetatags = "select * from metatags where language = '$language' and company = $company";
$resultMetatags = mysql_query($queryMetatags);
$numberMetatags = mysql_numrows($resultMetatags);
$description = mysql_result($resultMetatags,0,"description");

header ("Content-type: text/xml");

$lastBuildDate = date("r");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<rss version=\"2.0\">";
echo "<channel>";
echo "<title>conceptMonitor : An open source and freeware software version tracker by $webSiteName</title>";
echo "<link>http://$SERVER_NAME</link>";
echo "<description>ConceptMonitor is a Software Version Tracker that checks regularly project homepage of open source and freeware products and provided a one stop shop to check the version of the latest stable release.<br/>The list of software projects monitored currently is small, however anyone can contribute by requesting that a particular project is added to the list.</description>";
echo "<language>en-us</language>";
echo "<lastBuildDate>$lastBuildDate</lastBuildDate>";
echo "<category>Software Version Tracker</category>";
echo "<generator>http://$SERVER_NAME</generator>";
echo "<docs></docs>";
echo "<copyright>&#169; $webSiteName</copyright>";
echo "<managingEditor>$adminEmail</managingEditor>";
echo "<webMaster>$adminEmail</webMaster>";
echo "<image>";
echo "<url>http://$SERVER_NAME/images/logo.jpg</url>";
echo "<title>conceptMonitor : An open source and freeware software version tracker by $webSiteName</title>";
echo "<link>http://$SERVER_NAME</link>";
echo "</image>";
echo "<ttl>60</ttl>";

$query = "select * from monitor where deleteind = 'N' and status = 'L' and company = $company order by currentdate desc";

$result = mysql_query($query);
$number = mysql_numrows($result);

$i = 0;

if ($number != 0) {
   while ($i < $number) {
      $id = mysql_result($result,$i,"id");
      $name = mysql_result($result,$i,"name");
      $platform = mysql_result($result,$i,"platform");
      $url = mysql_result($result,$i,"url");
      $version = mysql_result($result,$i,"currentValue");
      $category = mysql_result($result,$i,"category");      
      $description = mysql_result($result,$i,"description");      
      $dateVersion = mysql_result($result,$i,"currentDate");
      $dateVersionFormat = fromMysqlDate($dateVersion);
      $dateVersionPubDate = date("r",strtotime($dateVersion));
      echo "<item>";
      if ($platform != "") {
         echo "<title>$name ($platform) version $version has been released on $dateVersionFormat</title>\n";
         echo "<description>$description</description>\n";
      else  {
         echo "<title>$name version $version has been released on $dateVersionFormat</title>\n";
         echo "<description>$description</description>\n";
      echo "<author>Alain Orset</author>\n";        
      echo "<category>$category</category>\n";          
      echo "<link>$url</link>\n";
      echo "<pubdate>$dateVersionPubDate</pubdate>\n";
      echo "</item>\n";
echo "</channel>";
echo "</rss>";

exit ?>

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

bartonjo2Author Commented:
So I could have a while loop that would print the latest 10 items in xml format?? alain34?
you have 2 way of doing that
- put a limit statement in the sql stament. in y exmaple it will be :
$query = "select * from monitor where deleteind = 'N' and status = 'L' and company = $company limit 0,10 order by currentdate desc";
- force $number to be 10 if the value produced is more than 10
$number = mysql_numrows($result);
if ($number > 10) {
   $number = 10;

first option is better!
bartonjo2Author Commented:
yeah the first option  will allow me to actually show the top ten because it will sort by currentdate and by the field flag  being T for topten... I will see if this works
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.