dvdflashbacks Posted June 30, 2008 Share Posted June 30, 2008 I can't seem to figure out how to make my RSS .xml file work. I have tried handcoding this a few times now and it doesn't seem to validate properly. Here is the link for it: http://www.nothingaboutnothing.com/rss.xml This is a dynamic blog type site, so I also can't seem to find an RSS app that will work, since most seem to only work with static html. Any suggestions? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/ Share on other sites More sharing options...
DarkWater Posted June 30, 2008 Share Posted June 30, 2008 When I check the source of the page, I saw: <?php header('Content-type:text/xml');?> <rss version="2.0"> <channel> <title>A BlogAboutNothing</title> <link>http://www.nothingaboutnothing.com/</link> <description>A BlogAboutNothing</description> <lastBuildDate>Mon, 12 Sep 2005 18:37:00 GMT</lastBuildDate> <language>en-us</language> <?php require_once('Connections/conndb.php'); ?> <?php mysql_select_db($database_conndb, $conndb); $query_Recordset1 = "SELECT blog_item_id, blog_item_datetime, blog_item_title, Left(blog_item, 150) as blog_item FROM blog_items ORDER BY blog_item_datetime DESC "; $Recordset1 = mysql_query($query_Recordset1, $conndb) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); while($result = mysql_fetch_array($Recordset1)){ ?> <item> <title><?=htmlentities(strip_tags($result['blog_item_title'])); ?></title> <description><?=htmlentities(strip_tags($result['blog_item'],'ENT_QUOTES')); ?></description> <link>http://www.nothingaboutnothing.com/archive.php?id=<?=$result['blog_item_id']; ?></link> <guid>http://www.nothingaboutnothing.com/archive.php?id=<?=$result['blog_item_id']; ?></guid> <pubDate><?php echo date('r',$row_Recordset1['blog_item_datetime']); ?></pubDate> </item> <? } ?> </channel> </rss> So therefore the PHP isn't executed because it's not a PHP file. How are you creating the RSS feed? You need to do all the stuff you did in that .xml file but in a PHP file and then output it to the XML file. Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-578427 Share on other sites More sharing options...
rhodesa Posted June 30, 2008 Share Posted June 30, 2008 You have a couple options... 1) Rename the file to .php and add this to the top: header('Content-type: text/xml'); 2) Tell Apache to send XML files through the PHP parser. To do that, create a .htaccess file in the same dir, and add this line to it: AddType application/x-httpd-php .xml 3) Put that script in a separate file, and have it write the output to the XML file. Then, set that script to run on a scheduled job, or when items in the database are updated. Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-578429 Share on other sites More sharing options...
dvdflashbacks Posted June 30, 2008 Author Share Posted June 30, 2008 Hey rhodesa, I changed the file type back to .php but I am not sure what you mean by having it write the ouput to an xml file. I was able to bring up the rss.php file but I am not sure what I am supposed to do with it now. Is this right: http://www.nothingaboutnothing.com/rss.php Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-578569 Share on other sites More sharing options...
DarkWater Posted June 30, 2008 Share Posted June 30, 2008 He was talking about different options. It's perfect right now, but just add this line as the VERY FIRST LINE, before ANY whitespace or output: <?php header('Content-type: text/xml'); ?> Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-578573 Share on other sites More sharing options...
dvdflashbacks Posted June 30, 2008 Author Share Posted June 30, 2008 Hi Darkwater, Ok, I checked and that line is at the top of the file exactly as you typed it. If you go to the link it shows the file now, but it doesn't have one of my most recent entries listed. I am not sure how these RSS are supposed to work, but I thought that it would update live after each entry that I add to the Blog. And I am not sure how to actually syndicate it for other people to subscribe. thanks. Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-578593 Share on other sites More sharing options...
DarkWater Posted June 30, 2008 Share Posted June 30, 2008 Well, what is it SUPPOSED to have on it? Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-578602 Share on other sites More sharing options...
dvdflashbacks Posted June 30, 2008 Author Share Posted June 30, 2008 Sorry, I fixed the date problem. But the RSS still doesn't show one of my latest blog entries which was from this weekend but I modified it today. It is a review for the movie Wanted. All the other entries come up though so that is kinda weird. Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-578607 Share on other sites More sharing options...
DarkWater Posted June 30, 2008 Share Posted June 30, 2008 Check your query and make sure it's doing everything correctly. Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-578609 Share on other sites More sharing options...
dvdflashbacks Posted June 30, 2008 Author Share Posted June 30, 2008 I do not see how the query could not be working since it is pulling up everything but 1 record. And this 1 record in fact displays on my actual site as the first record in the blog list (repeat region.) Sorry, I am not sure. I have never done RSS before. I looked at the query again though, and it looks correct from what I can tell. Very strange. Could it be the date at the top of the page. The build date say Sept of 2005??? Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-578620 Share on other sites More sharing options...
dvdflashbacks Posted June 30, 2008 Author Share Posted June 30, 2008 Hey Guys, Sorry to be a pain. So I have double and triple checked this thing. I can't see anything that is preventing this record from not displaying in the feed. I also found no way to unsubscribe to this feed when I was testing it out. So that is another weird problem. I ran the file through a validator and it looks like my date formats are not validating, so I am not sure if that is part of the problem. Any thoughts? Thanks. Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-578684 Share on other sites More sharing options...
rhodesa Posted June 30, 2008 Share Posted June 30, 2008 I'm trying to load it up, but it's broken...I can see the PHP code... is this the URL i'm supposed to be looking at? http://www.nothingaboutnothing.com/rss.php Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-578694 Share on other sites More sharing options...
dvdflashbacks Posted July 1, 2008 Author Share Posted July 1, 2008 Hey Rhodesa, Sorry, I have been experimenting all day with this. Here are the results so far: This version displays all records except the most recent: http://www.nothingaboutnothing.com/rss.php And this version displays only the latest record over and over: http://www.nothingaboutnothing.com/rss2.php I am totally lost on this. Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-578850 Share on other sites More sharing options...
rhodesa Posted July 1, 2008 Share Posted July 1, 2008 can you post the most updated code for each? i can see the results there but want to look at the PHP for each Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-579082 Share on other sites More sharing options...
dvdflashbacks Posted July 1, 2008 Author Share Posted July 1, 2008 Sorry, here they are. rss.php <?php header('Content-type:text/xml');?> <?php require_once('Connections/conndb.php'); ?> <?php mysql_select_db($database_conndb, $conndb); $query_Recordset1 = "SELECT blog_item_id, blog_item_datetime, blog_item_title, Left(blog_item, 250) as blog_item FROM blog_items ORDER BY blog_item_datetime DESC"; $Recordset1 = mysql_query($query_Recordset1, $conndb) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <rss version="0.92"> <channel> <title>A BlogAboutNothing</title> <link>http://www.nothingaboutnothing.com/</link> <description>A BlogAboutNothing</description> <language>en-us</language> <?php while($result = mysql_fetch_array($Recordset1)){ ?> <item> <title><?=htmlentities(strip_tags($result['blog_item_title'])); ?></title> <description><?=htmlentities(strip_tags($result['blog_item'])); ?></description> <link>http://www.nothingaboutnothing.com/archive.php?id=<?=$result['blog_item_id']; ?></link> <guid>http://www.nothingaboutnothing.com/archive.php?id=<?=$result['blog_item_id']; ?></guid> <pubDate><?=htmlentities(strip_tags($result['blog_item_datetime'])); ?></pubDate> </item> <? } ?> </channel> </rss> <?php mysql_free_result($Recordset1); ?> And the second one: rss2.php <?php header('Content-type:text/xml');?> <?php require_once('Connections/conndb.php'); ?> <?php mysql_select_db($database_conndb, $conndb); $query_Recordset1 = "SELECT blog_item_id, blog_item_datetime, blog_item_title, Left(blog_item, 250) as blog_item FROM blog_items ORDER BY blog_item_datetime DESC"; $Recordset1 = mysql_query($query_Recordset1, $conndb) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <rss version="0.92"> <channel> <title>A BlogAboutNothing</title> <link>http://www.nothingaboutnothing.com/</link> <description>A BlogAboutNothing</description> <language>en-us</language> <?php while($result = mysql_fetch_array($Recordset1)){ ?> <item> <title><?php echo $row_Recordset1['blog_item_title']; ?></title> <description><?php echo $row_Recordset1['blog_item']; ?></description> <link>http://www.nothingaboutnothing.com/archive.php?id=<?=$result['blog_item_id']; ?></link> <guid>http://www.nothingaboutnothing.com/archive.php?id=<?=$result['blog_item_id']; ?></guid> <pubDate><?php echo $row_Recordset1['blog_item_datetime']; ?></pubDate> </item> <? } ?> </channel> </rss> <?php mysql_free_result($Recordset1); ?> Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-579138 Share on other sites More sharing options...
rhodesa Posted July 1, 2008 Share Posted July 1, 2008 ok...let me try to explain the mysql_* functions... mysql_query() => Executes the SQL, and returns a pointer to a result set mysql_fetch_assoc() => Returns a row from the result set, and advances the cursor forward so, when you execute mysql_fetch_assoc() right after the query (but before the loop), you are basically throwing away a record. this is what the code should be: <?php header('Content-type:text/xml'); require_once('Connections/conndb.php'); mysql_select_db($database_conndb, $conndb); $sql = "SELECT blog_item_id, blog_item_datetime, blog_item_title, Left(blog_item, 250) as blog_item FROM blog_items ORDER BY blog_item_datetime DESC"; $result = mysql_query($sql, $conndb) or die(mysql_error()); ?> <rss version="0.92"> <channel> <title>A BlogAboutNothing</title> <link>http://www.nothingaboutnothing.com/</link> <description>A BlogAboutNothing</description> <language>en-us</language> <?php while($row = mysql_fetch_assoc($result)){ ?> <item> <title><?=htmlspecialchars(strip_tags($row['blog_item_title'])); ?></title> <description><?=htmlspecialchars(strip_tags($row['blog_item'])); ?></description> <link>http://www.nothingaboutnothing.com/archive.php?id=<?=$row['blog_item_id']; ?></link> <guid>http://www.nothingaboutnothing.com/archive.php?id=<?=$row['blog_item_id']; ?></guid> <pubDate><?=htmlspecialchars(strip_tags($row['blog_item_datetime'])); ?></pubDate> </item> <? } ?> </channel> </rss> Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-579163 Share on other sites More sharing options...
dvdflashbacks Posted July 1, 2008 Author Share Posted July 1, 2008 Hi Rhodesa, Thanks for this info. Unfortunately, it is the same result, well actually it says that the page has errors on it. ??? Here is the code that I entered just so you can compare and make sure I didn't type anything wrong (I tried doing a copy paste, but my code editor didn't seem to grab things right from the clip board.) <?php header('Content-type:text/xml'); require_once('Connections/conndb.php'); mysql_select_db($database_conndb, $conndb); $sql = "SELECT blog_item_id, blog_item_datetime, blog_item_title, Left(blog_item, 250) as blog_item FROM blog_items ORDER BY blog_item_datetime DESC"; $result = mysql_query($sql, $conndb) or die(mysql_error()); ?> <rss version="0.92"> <channel> <title>A BlogAboutNothing</title> <link>http://www.nothingaboutnothing.com/</link> <description>A BlogAboutNothing</description> <language>en-us</language> <?php while($row = mysql_fetch_assoc($result)){ ?> <item> <title><?=htmlspecialchars(strip_tags($row['blog_item_title'])); ?></title> <description><?=htmlspecialchars(strip_tags($row['blog_item'])); ?></description> <link>http://www.nothingaboutnothing.com/archive.php?id=<?=$row['blog_item_id']; ?></link> <guid>http://www.nothingaboutnothing.com/archive.php?id=<?=$row['blog_item_id']; ?></guid> <pubDate><?=htmlspecialchars(strip_tags($row['blog_item_datetime'])); ?></pubDate> </item> <? } ?> </channel> </rss> Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-579222 Share on other sites More sharing options...
rhodesa Posted July 1, 2008 Share Posted July 1, 2008 make sure there is no extra white space at the very beginning of the file...before the first <?php tag Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-579232 Share on other sites More sharing options...
dvdflashbacks Posted July 1, 2008 Author Share Posted July 1, 2008 I do not see any white space. This is crazy. Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-579248 Share on other sites More sharing options...
rhodesa Posted July 1, 2008 Share Posted July 1, 2008 what editor are you using? sometimes when you copy/paste, you will get weird hidden characters. can you email me the file and I'll take a look at it? Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-579254 Share on other sites More sharing options...
dvdflashbacks Posted July 1, 2008 Author Share Posted July 1, 2008 Just sent you the file. Also got two weird errors when I tried to validate using a feed validator online. This feed does not validate. line 1, column 0: Undefined root element: br [help] <br />line 2, column 0: XML parsing error: <unknown>:2:0: junk after document element [help] <b>Parse error</b>: syntax error, unexpected ':' in <b>/home/dvdflas1/publi ...In addition, interoperability with the widest range of feed readers could be improved by implementing the following recommendation. Feeds should not be served with the "text/html" media type [help] Thanks. Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-579282 Share on other sites More sharing options...
dvdflashbacks Posted July 1, 2008 Author Share Posted July 1, 2008 Big thanks to Rhodesa for fixing this problem for me. Here is the final output which now works for anyone that runs into anything similar: <?php /** * Use FULL php tags, not the short <? as some PHP * installs may not be configured to use them * * In the header() function, it had MSWord style quotes * around it. I changed them to normal quotes * * Requires should come at the beginning */ require_once('Connections/conndb.php'); ?> <rss version="0.92"> <channel> <title>A BlogAboutNothing</title> <link>http://www.nothingaboutnothing.com/</link> <description>A BlogAboutNothing</description> <language>en-us</language> <?php mysql_select_db($database_conndb, $conndb) or die(mysql_error()); $sql = "SELECT blog_item_id, blog_item_datetime, blog_item_title, Left(blog_item, 250) as blog_item FROM blog_items ORDER BY blog_item_datetime DESC"; $result = mysql_query($sql, $conndb) or die(mysql_error()); /** * The WHILE loop was missing here...i added it back */ while($row = mysql_fetch_array($result)){ ?> <item> <title><?=htmlspecialchars(strip_tags($row['blog_item_title'])); ?></title> <description><?=htmlspecialchars(strip_tags($row['blog_item'])); ?></description> <link>http://www.nothingaboutnothing.com/archive.php?id=<?=$row['blog_item_id']; ?></link> <guid>http://www.nothingaboutnothing.com/archive.php?id=<?=$row['blog_item_id']; ?></guid> <pubDate><?=htmlspecialchars(strip_tags($row['blog_item_datetime'])); ?></pubDate> </item> <?php } ?> </channel> </rss> The two changes that I had to make on Rhodesa revised file is that I had to remove the header line (all of my other research indicates that this line is needed for the RSS feed to work properly if it is not an xml file) and I also had to rename the file to something other than rss.php. I believe these two inconsistencies are configurational issues or bugs with my hosting company. But I don't really know. But it now works correctly! Thanks also to everyone who gave feedback on this. Link to comment https://forums.phpfreaks.com/topic/112631-solved-rss-feed-not-validating-correctly/#findComment-579585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.