I'm so close to creating my RSS feed but I need help!!!

Discussion in 'XML & RSS' started by craigwg, Oct 29, 2009.

  1. #1
    I've read through dozens of tutorials on creating RSS feeds for my PHP/MySQL site, each with a different approach. It's maddening that NONE of them have worked. They all have quirks. I think I'm VERY close but I'm arguing with apostrophies and semi-colons. HELP!

    Here is the text I have created (password changed to protect the innocent):

    
    <?
    header("Content-type: application/rss+xml");
    ?>
    <?  
    $chan_title = "www.CraigGreenwood.com";
    $chan_link = "http://www.craiggreenwood.com/journal.php/";
    $chan_desc = "Keep up on the life and times of Craig Greenwood.";
    ?>
    <?
    $db_user = 'craiggr_craigwg';
    $db_pass = 'changedtoprotectinnocent';
    $db_host = 'localhost';
    $db_database = 'craiggr_craigcom';
    $db = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
    mysql_select_db($db_database);
    ?>
    <?
    $query = "SELECT date, entry FROM tblJournal ORDER BY date DESC LIMIT 15";
    $result = mysql_query($query) or die(mysql_error());
    if (mysql_num_rows($result) < 1) {
        die("No records");
    }
    ?>
    <?
    $items = '';
    while ($row = mysql_fetch_assoc($result)) {
        $item_title = $row["date"];
        $item_link = $row["http://www.CraigGreenwood.com/journal.php/"];
        $item_desc = $row["entry"];
        $items .='<item>
                <title>$item_title</title>
                <link>$item_link</link>
                <desc>$item_desc</desc>
            </item>';}
    ?>
    <?
    $content ='<?xml version="1.0" encoding="UTF-8"?>
    <rss version="2.0">
            <channel>
                    <title>$chan_title</title>
                    <link>http://www.craiggreenwood.com/journal.php/</link>
                    <description>$chan_desc</description>
    $items
            </channel>
    </rss>';?>
    <? print $content; ?>
    
    Code (markup):
    I try to validate at http://beta.feedvalidator.org/ and it DIES. The $items variable is very clear to my eyes. I can't see what I'm missing. Please help me!

    Thanks
    Craig
     
    craigwg, Oct 29, 2009 IP
  2. craigwg

    craigwg Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I got an email that this post was updated with a question asking to write the mysql table. I hope this is the right place to answer it.

    The table is very simple and straightforward, designed by me.

    Table name: tblJournal
    ID: int(11) auto_increment
    entry: longtext
    Title: varchar(50)
    Category: varchar(20)
    date: timestamp

    The table has about 117 rows so its pretty small. But I still want my RSS feed working!

    Thanks for your help.
    Craig
     
    craigwg, Nov 2, 2009 IP