SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Michigan
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I write an RSS feed while pulling the data from a mysql table?

    My problem is probably simple, but I'm an idiot and don't understand a lot of this RSS/XML stuff. I want to create a simple XML file, like this: http://www.w3schools.com/xml/note.xml

    An everything works fine and dandy, but what if I need to pull that info from a mysql database (using PHP)? I tried both sticking the PHP code in the XML file and writing a PHP file using header("Content-type: text/xml") and neither have worked. What do I need to do?

    Thanks,
    C

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)

  3. #3
    SitePoint Guru marcel's Avatar
    Join Date
    Nov 2000
    Posts
    920
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i use xmlwriter from phpclasses.org

    by manuel llemos

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Michigan
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still can't get this to work. I've noticed on thing: when I include these two lines:

    <rss version="2.0">
    <channel>

    Nothing displays and I get the following source code:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD>
    <META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
    <BODY></BODY></HTML>
    Yet when I do not include those lines, it writes the source exactly as in the link above, but it does not display in RSS form. It just displays the text without the XML tags. I presume this is because it's a PHP page and not an XML page. But I've tried both header ("Content-type: text/xml") and header ("Content-type: application/rss+xml") and neither have solved the problem. Could this be an issue with my host?

  5. #5
    SitePoint Addict KelliShaver's Avatar
    Join Date
    Mar 2003
    Location
    Morehead, KY
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm on my way out the door, so I don't have time to go thorugh what you've already got here, but maybe this will help you....

    http://synapse.kellishaver.com/index...xml_on_the_fly

  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Michigan
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KelliShaver
    I'm on my way out the door, so I don't have time to go thorugh what you've already got here, but maybe this will help you....

    http://synapse.kellishaver.com/index...xml_on_the_fly
    Yeah, that does help, thanks. It writes the XML source code, but it still does not display the RSS feed. IT just displays the text without the XML tags or any HTML formatting. What else could be going wrong. My whole source code is:
    PHP Code:
    <?php
        header 
    ("Content-type: application/xml"); 
        
        
    $myChannel['title'] = "My Channel";
        
    $myChannel['description'] = "This is my test channel.";
        
    $myChannel['link'] = "http://synapse.kellishaver.com/feed.xml";
        
        
    $myItems[0]['title'] = "My Item";
        
    $myItems[0]['description'] = "This is my first sample item.";
        
    $myItems[0]['link'] = "http://synapse.kellishaver.com";
        
        
    $myItems[1]['title'] = "My 2nd Item";
        
    $myItems[1]['description'] = "This is my second sample item.";
        
    $myItems[1]['link'] = "http://www.kellishaver.com";
        
    function 
    printXML($channel$items) {
        
    // Start our XML output
        
    print "<"."?xml version=\"1.0\" ?".">\n<rss version=\"2.0\">";

        
    // Print channel info from array.
        
    printf('
        <channel>
            <title>%s</title>
            <description>%s</description>
            <link>%s</link>'
    ,
            
    $channel['title'],
            
    $channel['description'],
            
    $channel['link']
        );

        
    // Loop through our 2d items array and print the info for each item
        
    for($i=0;$i<count($items);$i++) {
            
    printf('
            <item>
                <title>%s</title>
                <description>%s</description>
                <link>%s</link>
            </item>'
    ,
                
    $items[$i]['title'],
                
    $items[$i]['description'],
                
    $items[$i]['link']
            );
        }

        
    // Close our feed.
        
    print "\n    </channel>\n</rss>";
    }

        
    printXML($myChannel$myItems);
    ?>
    I copied it exactly, but I had to change some variable and function names for it to work.

  7. #7
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make sure you have something like this in your .htaccess. Then try displaying your feed again.

    Code:
    AddType application/xml rss
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  8. #8
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Michigan
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vinyl-junkie
    Make sure you have something like this in your .htaccess. Then try displaying your feed again.

    Code:
    AddType application/xml rss
    Nope. Does the .htaccess go in the same folder as the file making the RSS? I have a .htaccess in the parent folder. Would that cause any problems, having two in the same site?

    Chris

  9. #9
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Are you using Opera? Some browsers actually parse the XML and display the text inside of its tags.

    What browser version are you using and on what platform?

  10. #10
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Hartmann
    Are you using Opera? Some browsers actually parse the XML and display the text inside of its tags.

    What browser version are you using and on what platform?
    and do you have a link?

  11. #11
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Michigan
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Somehow, it is working now. I don't know what I did, but thanks for all the help.

    C


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •