nicky666 Posted January 28, 2014 Share Posted January 28, 2014 Hi i'm trying to create a rss page, the problem I have is that the data is not showing. If I check the page source the data is there but it's not showing up and I can't seem to figure out why or how to fix it. <?php ini_set('display_errors', 1); header("Content-type: text/xml"); include("includes/database.php"); global $NEWS; $str = '<?xml version="1.0" encoding="UTF-8"?>'; $str.= '<rss version="2.0">'; $str.='<channel>'; $sql = "SELECT * FROM news"; $result = mysql_query($sql) or die ($sql."".mysql_error()); while($row = mysql_fetch_object($result)){ $str.= '<item>'; $str.= '<title>'.$row->title.'</title>'; $str.= '<description>'.$row->content. '</description>'; $str.= '</item>'; } $str .='</channel>'; $str .='</rss>'; echo $str; Link to comment https://forums.phpfreaks.com/topic/285743-while-loop-not-showing-anything/ Share on other sites More sharing options...
cyberRobot Posted January 28, 2014 Share Posted January 28, 2014 Is that the entire code? If so, you're missing the closing PHP tag. //... echo $str; ?> If that doesn't work, have you tried validating the feed? http://validator.w3.org/feed/ Link to comment https://forums.phpfreaks.com/topic/285743-while-loop-not-showing-anything/#findComment-1466850 Share on other sites More sharing options...
nicky666 Posted January 28, 2014 Author Share Posted January 28, 2014 I validated the feed and I got this This feed does not validate. line 1, column 113: Undefined description element: p [help] ... title>xzfbcbcxv 123</title><description><p>Mr. Kim Keats-Martínez, Execu ... ^ line 1, column 116: XML parsing error: <unknown>:1:402: not well-formed (invalid token) [help] ... le>xzfbcbcxv 123</title><description><p>Mr. Kim Keats-Martínez, Executiv ... I'm not sure how I'm going to fix this as the cms I'm using puts the <p> tag automatically Link to comment https://forums.phpfreaks.com/topic/285743-while-loop-not-showing-anything/#findComment-1466852 Share on other sites More sharing options...
Ch0cu3r Posted January 28, 2014 Share Posted January 28, 2014 You need to contain your HTML within CDATA. Otherwise the XML parser thinks it is part of your XML structure and so you'll get validation errors. $str.= '<description><![CDATA['.$row->content. ']]></description>'; Alternatively convert the html to htmlentities Link to comment https://forums.phpfreaks.com/topic/285743-while-loop-not-showing-anything/#findComment-1466854 Share on other sites More sharing options...
nicky666 Posted January 28, 2014 Author Share Posted January 28, 2014 Thank you so much Ch0cu3r that worked Link to comment https://forums.phpfreaks.com/topic/285743-while-loop-not-showing-anything/#findComment-1466856 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.