RSS and a MySQL php database.

Discussion in 'XML & RSS' started by Ted E Bare, Apr 19, 2006.

  1. #1
    Hi All

    I've already posted this on a different forum, but I thought I might have more luck here. I post news on my site through a MySQL database. I was wondering if there is anyway to turn this into an rss feed or does php not work in rss?

    Here is what I have:

    ____________________________________

    <table border="0" cellpadding="3">
    <?php
    $username="";
    $password="";
    $database="";

    $day="0";
    $month="0";
    $year="0";

    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");

    $query="SELECT * FROM news WHERE category = 'CA' ORDER BY date DESC LIMIT 0, 10";
    $result=mysql_query($query);

    $num=mysql_numrows($result);

    mysql_close();

    $i=0;
    while ($i < $num) {
    $date=mysql_result($result,$i,"date");
    $news=mysql_result($result,$i,"news");
    $category=mysql_result($result,$i,"category");

    list($year, $month, $day) = split("-", $date, 3);

    if ($month == "01") { $month = "January"; }
    elseif ($month == "02") { $month = "February"; }
    elseif ($month == "03") { $month = "March"; }
    elseif ($month == "04") { $month = "April"; }
    elseif ($month == "05") { $month = "May"; }
    elseif ($month == "06") { $month = "June"; }
    elseif ($month == "07") { $month = "July"; }
    elseif ($month == "08") { $month = "August"; }
    elseif ($month == "09") { $month = "September"; }
    elseif ($month == "10") { $month = "October"; }
    elseif ($month == "11") { $month = "November"; }
    elseif ($month == "12") { $month = "December"; }

    echo "<tr>";

    echo "<td align=\"left\" valign=\"top\" width=\"105\">";
    echo "<font><b>$day $month $year</b></font>";
    echo "</td>";

    echo "<td align=\"left\" valign=\"top\">";
    echo "<font>$news</font>";
    echo "</td>";

    echo "</tr>";

    $i++;
    }
    ?>
    </tr>
    </table>
    ____________________________________

    The result looks like this:

    18 March 2006 Applications are now open...
    14 March 2006 The deadline is only weeks away...
    etc.

    Is there anyway to set it up so that the date is the title and the news bit is the description, or would I have to do the RSS manually?

    Thanks,
    Peter
     
    Ted E Bare, Apr 19, 2006 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,830
    Likes Received:
    4,541
    Best Answers:
    123
    Trophy Points:
    665
    #2
    Just write a new script to echo out the information like an RSS feed does and have this at the top:
    header('Content-type: text/xml;');
    Code (markup):
    you know the basic structure of a feed right? doesn't have to be anything fancy.
     
    sarahk, Apr 20, 2006 IP