?
Solved

php rss

Posted on 2005-04-18
6
Medium Priority
?
269 Views
Last Modified: 2008-02-01
How would I create an rss that is generated by php and uses db values?
0
Comment
Question by:bartonjo2
6 Comments
 
LVL 14

Accepted Solution

by:
cracky earned 500 total points
ID: 13812302
0
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 13812361
0
 
LVL 16

Expert Comment

by:alain34
ID: 13813250
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 http://blogs.law.harvard.edu/tech/rss

<?php

/* connection to the database and standard function */
require("functions.php");

/* 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>http://blogs.law.harvard.edu/tech/rss</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";
      $i++;
      }
   }
echo "</channel>";
echo "</rss>";

mysql_close();
exit ?>

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:bartonjo2
ID: 13814109
So I could have a while loop that would print the latest 10 items in xml format?? alain34?
0
 
LVL 16

Expert Comment

by:alain34
ID: 13814270
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!
0
 
LVL 3

Author Comment

by:bartonjo2
ID: 13814287
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
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month15 days, 18 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question