Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Nov 2007
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    RSS Xml output using php

    hi guys im trying to get a clean XML output using php and mysql, to make a dynamic rss feed , but i cant find whats the problem with my script, if any1 have any idea it will be very appreciated, here is the code.

    Code:
    <?php
    include("dbinfo.inc.php");
    $dbconnect = mysql_pconnect(localhost,$username,$password);
    mysql_select_db($database, $dbconnect);
    $query = "SELECT id, title, itemcomment, picturelink FROM jos_seyret_items WHERE featured='1' order by id desc limit 15";
    $result = mysql_query($query, $dbconnect);
    
    while ($line = mysql_fetch_assoc($result))
            {
                $return[] = $line;
            }
    
    $now = date("D, d M Y H:i:s T");
    
    
    $output = "<?xml version=\"1.0\"?>
                <rss version=\"2.0\">
                    <channel>
                        <title>What's hot</title>
                        <link>http://www.webcastr.com/RSS/whatshot.php</link>
                        <description>Latest Video on webcastr.com</description>
                        <language>en-us</language>
                        <pubDate>$now</pubDate>
                        
                ";
                
    foreach ($return as $line)
    {
        $output .= "<item><title>".htmlentities($line['title'])."</title>
                        <link>http://www.webcastr.com/index.php?option=com_seyret&Itemid=27&task=videodirectlink&id=".htmlentities($line['id'])."</link>
                        
    <description>".htmlentities(strip_tags($line['itemcomment']))."</description>
                    </item>";
    }
    $output .= "</channel></rss>";
    header("Content-Type: application/rss+xml");
    echo $output;
    ?>

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    what isn't working? You mention a problem, but don't say what it is, it's far less effort for someone to look for the cause of a particular problem than it is to look for one of the many possible issues that could happen when reading from a database and writing to XML (assuming you haven't screwed up something more trivial...)
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #3
    New Coder
    Join Date
    Nov 2007
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    sorry about that, i was trying to validate it using feedvalidator.org and this came up.

    This feed does not validate.
    line 1, column 1: XML parsing error: <unknown>:1:1: xml declaration not at start of external entity

    but the true is not sure whats the problem, this php code should give me a clean xml output from our database and the idea was after i get this output parse it using megpie liebrary or something simmilar. but looking at the print, i can find whats wrong with the xml output or the error declaration.

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,009
    Thanks
    2
    Thanked 312 Times in 304 Posts
    Have you checked that the output is what you expect? Are there any php error messages being output in the content?

    After you make sure that the output is what you expect, make sure that the .php file (or if this is a .xml file, is your server setup to parse it through the php language engine?) is saved as an ANSI/ASCII file and not UTF-8 or Unicode (which would be outputting extra language characters before the <?php tag.)
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,009
    Thanks
    2
    Thanked 312 Times in 304 Posts
    Once you get to the point of actually validating the output, you will find that the & in the link need to be changed to &amp;
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #6
    New Coder
    Join Date
    Nov 2007
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    gotcha, will get into this right now, thanks a lot for the hints :P


  •  

    Posting Permissions

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