MySQL DB -> RSS?

Discussion in 'XML & RSS' started by matstars, Nov 5, 2008.

  1. #1
    I have a site that I update via a PHP script that I wrote - it stores all the information in a MySQL database. Is there any way I can have that database automatically send it as an RSS feed of sorts? I can put it in the "add news" script.

    Thanks,

    Matstars
     
    matstars, Nov 5, 2008 IP
  2. lruneh

    lruneh Peon

    Messages:
    72
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What you want to do is query the database and echo it as rss formatted xml.
    The code is untested...
    
    echo"<?xml version='1.0' encoding='UTF-8'?>"; ?>
    
    <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    
    <channel>
    <title>title</title>
    <description>description</description>
    <link>link/</link>
    <lastBuildDate><?php echo date(r);?></lastBuildDate>
    <pubDate>Fri, 22 Aug 2008 22:47:37 +0200</pubDate>
    <?php 
    $sql = mysql_query("SELECT * FROM table_name");
    
    while ($row = mysql_fetch_array($sql)){
    $desc=$row['article'];
    //strip the content from tags in conflict with rss
    $desc=strip_tags($desc);
    
    //echo the elements of each item
    }
    ?>
    
    </channel>
    </rss>
    
    Code (markup):
    This should point you in the right direction.
     
    lruneh, Nov 5, 2008 IP
  3. megawallz

    megawallz Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You can also use a php class called FeedCreator.class.php

    The link is Here
     
    megawallz, Nov 7, 2008 IP