Jump to content
Larry Ullman's Book Forums

Recommended Posts

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

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

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.

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...