Jonathon Posted April 24, 2011 Share Posted April 24, 2011 I was just looking over Larry's chapter on RSS feeds and I notidced my in my feed that I'm having a strange occurance. Using this line: <pubDate>' . $row[3] . '</pubDate> Now in firefox this does return the date of "12 February 2011 00:00". Which is nice of firefox, but i doubted that all browsers would be so lenient. Tried Chrome and it didnt return the date. I've tried to format the date (which i did initially and hadn't noticed it wasn't working) using date('r', $row[3]) But this always returns: Thu, 01 Jan 1970 01:33:31 +0100 Which is bugging me, i've tried various attempts to fix it to no avail. my field is in datetime format too. and this is my query $q = "SELECT title, link, LEFT(content, 200), date_added AS date FROM blog ORDER BY date ASC"; Link to comment Share on other sites More sharing options...
Larry Posted April 25, 2011 Share Posted April 25, 2011 There's not really enough here for me to help debug. Link to comment Share on other sites More sharing options...
Jonathon Posted April 25, 2011 Author Share Posted April 25, 2011 What would you need Larry? The whole file? If so here it is: <?php /* This script will create an RSS feed */ // Send the content type=header header('Content-type: text/xml'); // Create the initial RSS code echo '<?xml version="1.0"?> <rss version="2.0"> <channel> <title>My Blog</title> <description>The most recent blogs</description> <link>http://www.website.com/blog</link>'; // Connect to the database $dbc = mysqli_connect('localhost', 'root', '', 'db_name') OR die ("error con</channel>\n<rss>\n"); // Define query $q = "SELECT title, link, LEFT(content, 200), date_added AS date FROM blog ORDER BY date ASC"; $r = mysqli_query($dbc,$q); while ($row = mysqli_fetch_array($r, MYSQLI_NUM)) { // Print each record as an item echo '<item> <title>' . htmlentities($row[0]) . '</title> <description>' . htmlentities($row[2]) . '[...]</description> <link>http://www.website.com/blog/' . $row[1] . '</link> <guid>http://www.website.com/blog/' . $row[1] . '</guid> <pubDate>' . $row[3] . '</pubDate> </item>'; } // End of while loop ?> Link to comment Share on other sites More sharing options...
Stuart Posted April 25, 2011 Share Posted April 25, 2011 Pretty sure the issue's just that you're passing a DATETIME to the date() function rather than a Unix timestamp? Just wrap it in UNIX_TIMESTAMP(date_added) AS date. I'm guessing the example in PHP5 is a timestamp column rather than DATETIME. 1 Link to comment Share on other sites More sharing options...
Jonathon Posted April 25, 2011 Author Share Posted April 25, 2011 Yes, well done to you Link to comment Share on other sites More sharing options...
Recommended Posts