tags:

views:

28

answers:

0

Forgive me if this is a homework question, trying to write an RSS feed for the first time. I have some code that someone hacked together but we want to update it to our new database. The new feed will pull from an ITEMS table doesn't need to be broken up by book, movie, etc.

  <?php header('Content-type: text/xml'); ?>
    <rss version="2.0">
    <channel>
    <title>neighborrow</title>
    <description>Borrow these items!</description>
    <link>http://www.a.neighborrow.com/&lt;/link&gt;
    <copyright>2007</copyright>
    <?php
    require_once('phpIncludes/database.php');
    function getItemType($itemType) {
        switch ($itemType) {
            case "book":
                return "book";
            case "movi":
                return "movie";
            case "musi":
                return "music";
            case "game":
                return "game";
            case "misc":
                return "misc";
        }
        return null;
    }
    $query=database("select bookID as itemID, title as title, 'book' as itemType, entered from books where `type` = 'Public'
        union
        select movieID as itemID, title as title, 'movi' as itemType, entered from movies where `type` = 'Public'
        union
        select musicID as itemID, album as title, 'musi' as itemType, entered from music where `type` = 'Public'
        union
        select gameID as itemID, title as title, 'game' as itemType, entered from games where `type` = 'Public'
        union
        select miscID as itemID, title as title, 'misc' as itemType, entered from misc where `type` = 'Public'
        order by entered DESC
        Limit 20 offset 0");

    while($row = mysql_fetch_array($query)){
    ?>
        <item>
          <title><?=$row['title']?></title>
          <link><?php echo "http://www.neighborrow.com/viewitem.php?type=".getItemType($row["itemType"])."&amp;amp;".getItemType($row["itemType"])."ID=".$row['itemID']?&gt;&lt;/link&gt;
          <guid isPermaLink="false"><?php echo getItemType($row["itemType"]).$row['itemID'];?></guid>
          <description>Category: <?=ucfirst(getItemType($row["itemType"])) ?></description>
    </item>
    <?php } ?>
    </channel>
    </rss>

am pretty sure the first thing i need to do is update the sql query to reflect the new db... is that right?

$query=database("select item from items where
order by entered DESC
Limit 20 offset 0");