1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Update RSS feed with PHP

Discussion in 'PHP' started by themlife, Dec 24, 2007.

  1. #1
    Hi there.

    I am looking for an easy way to update my RSS feed via a form. So at the end of the day I can enter a number into the form and it will update my feed dynamically.

    I need the bit of code that would grab the information from the mysql table and then format the php into a proper RSS code. Can anyone help out? Thanks!
     
    themlife, Dec 24, 2007 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    hi

    I can do this for $50

    50% advance

    Regards

    Alex
     
    kmap, Dec 25, 2007 IP
  3. bfellow

    bfellow Active Member

    Messages:
    266
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    78
    #3
    Try this out:

    
    <?php
    
    // Database settings
    
    $dbhost = 'localhost'; // your host name, default is localhost
    $dbuser = 'username'; // your database username
    $dbpass = 'passwordhere'; // your database password
    $dbname = 'databasename'; // your database name
    mysql_connect($dbhost,$dbuser,$dbpass) or die ("I could not connect!");
    // Select and connect to the database
    mysql_select_db($dbname) or die (mysql_error()); 
    
    // Start the RSS Feed
    
    header('Content-type: text/xml'); // Must declare the content type
    echo '<?xml version=\'1.0\' encoding=\'UTF-8\'?>';
    
    // Set RSS version.
    
    echo '
    <rss version=\'2.0\'> ';
    
    // Start the XML.
    
    echo '
    <channel>
    <title>Your Website</title>
    <description>Description of your website</description>
    <link>http://www.yourwebsite.com/</link>';
    
    // Query database and select the last 10 entries.
    
    $data = mysql_query('SELECT * FROM table ORDER BY id DESC LIMIT 10');
    while($row = mysql_fetch_array($data))
    {
    echo '
    <item>
    <link>http://www.yourwebsite.com/#'.$row['id'].'</link>
    <title>'.$row['title'].'</title>
    <description>'.$row['description'].'</description>
    </item>';
    }
    
    // The "while" statement loops and grabs the 
    //last 10 items as we stated in our $data query.
    
    // The <link> provides us with an anchor to the post 
    //on the main page.  It is using the post ID from the database.
    
    echo '
    </channel>
    </rss>';
    ?>
    
    
    Code (markup):
    This will grab the last ten items from your DB and format them into an RSS feed. That way when ever the script is called, your RSS feed updates.

    Hope this helps!:)
     
    bfellow, Dec 26, 2007 IP
    hogan_h and themlife like this.
  4. themlife

    themlife Peon

    Messages:
    105
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    bfellow, you are great! Everything worked just as I wanted it to! Thank you!!!!
     
    themlife, Dec 26, 2007 IP