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 7 of 7
  1. #1
    New Coder
    Join Date
    Dec 2005
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts

    RSS Feed valid but not working

    Hi I just tried my firt PHP RSS feed. I built the code like I would an HTML file from a PHP script.

    The DB query works, I tested it in phpMyAdmin, the feed validates at feedvalidator.org but the page remains empty.

    I wonder what's wrong with my code:

    Code:
    <?xml version="1.0"?>
    <?php header("Content-type: text/xml"); ?>
    <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    
    <channel>
    <atom:link href="http://www.MYSITE.com/result_news.xml" rel="self" type="application/rss+xml" />
    
    <title>MYSITE.com || News</title>
    <description>News from my community</description>
    <link>http://www.MYSITE.com/news</link>
    
    <?php
    $filename = "inc/XXXX.php";
    if (file_exists($filename)) include("inc/XXXX.php"); 
    
    	$query_news = "
    		SELECT id, news_title, party_group ,city, state, country
    		FROM news 
    		WHERE date_start <= CURDATE() AND date_end >= CURDATE() 
    		AND live = '1'
    		ORDER BY date_created DESC 
    		LIMIT 0,15 
    		";
    	$result_news = mysql_query($query_news)
    	or die ("Couldn't execute the News query.");
    
    	while ($row_news = mysql_fetch_array($result_news))
    	{
    	extract($row_news);
    	$h_news_title 	= html_entity_decode($news_title, ENT_QUOTES, "UTF-8");
    	$h_party_group 	= html_entity_decode($party_group, ENT_QUOTES, "UTF-8");
    	$h_city 		= html_entity_decode($city, ENT_QUOTES, "UTF-8");
    	$h_country 		= html_entity_decode($country, ENT_QUOTES, "UTF-8");
    	echo "<item>\n";
    	echo "<title>".$h_news_title."</title>\n";
    	echo "<description>".$h_news_title."</description>\n";
    	echo "<link>http://www.MYSITE.com/pl.php?p=news_item.php&amp;id=".$id."&amp;section=news</link>\n";
    	echo "</item>\n";
    	}
    ?>
    
    
    </channel>
    </rss>

  • #2
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    cursory glance code looks good xml looks formatted correctly have you tried looking at the feed in something other than a web browser ? if it appears blank in a web browser have you tried viewing source see if its there just the web browser being special and not displaying it?

    Have you tried adding in some debugs ie: echo "1"; echo "2"; etc after every execution line so you can see if its actually doing anything at all or just failing and not reporting an error.

    Edit: also look at http://www.codingforums.com/external.php and compare against your's for formatting just to be sure
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #3
    New Coder
    Join Date
    Dec 2005
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    After looking at this link, I wondered if the issue could be the file extension. I am using .xml and the codingforums link uses .php.
    I tried but it didn't make a difference.

    I added some echo as well and nothing showed up.

    I am wondering if PHP is simply not being parsed. Could it be a server setting?

  • #4
    New Coder
    Join Date
    Dec 2005
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I also tried a stand-alone news reader and nothing showed up.

  • #5
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    for it to process your php code the file would have to be called .php for starters something like rss.php is fine

    I've just cut the DB stuff out of your code and ran it against my local server

    PHP Code:
    <?xml version="1.0"?>
    <?php header
    ("Content-type: text/xml"); ?>
    <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
    <atom:link href="http://www.MYSITE.com/result_news.xml" rel="self" type="application/rss+xml" />
    <title>MYSITE.com || News</title>
    <description>News from my community</description>
    <link>http://www.MYSITE.com/news</link>
    <?php
    $h_news_title 
    "title";
    $id="ID";
        echo 
    "<item>\n";
        echo 
    "<title>".$h_news_title."</title>\n";
        echo 
    "<description>".$h_news_title."</description>\n";
        echo 
    "<link>http://www.MYSITE.com/pl.php?p=news_item.php&amp;id=".$id."&amp;section=news</link>\n";
        echo 
    "</item>\n";
    ?>
    </channel>
    </rss>
    Output

    Code:
    <?xml version="1.0"?>
    <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
    <atom:link href="http://www.MYSITE.com/result_news.xml" rel="self" type="application/rss+xml" />
    <title>MYSITE.com || News</title>
    <description>News from my community</description>
    <link>http://www.MYSITE.com/news</link>
    <item>
    <title>title</title>
    <description>title</description>
    <link>http://www.MYSITE.com/pl.php?p=news_item.php&amp;id=ID&amp;section=news</link>
    
    </item>
    </channel>
    </rss>
    Change your &amp; to just & its xml not html.

    asside from that I suspect the problem is with your select and while ()
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #6
    New Coder
    Join Date
    Dec 2005
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi all, I feel like a fool! I forgot my db connection script so there was no db connection. Now after a few adjustments, it is working.

    Thank you for you help!

  • #7
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by hinch View Post
    Change your &amp; to just & its xml not html.
    exactly for this reason must be &amp; and not &.

    regards


  •  

    Posting Permissions

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