...

View Full Version : RSS feed date not right, it says its like 12900 days old when we add info today!



jasonc310771
01-04-2008, 06:05 PM
<?php
header('Content-type: text/xml');
include("dbconfig.php");

// the DATE_FORMAT is to make the date RFCwhatsit compliant
$whatmonth = gmdate('m'); $whatyear = gmdate('Y'); $datetocheck = gmdate("Y-m-d H:i:s");
$resultset = mysql_query("SELECT * FROM `sites` WHERE `confirmed` = '1' AND `linklocation` = 'main' AND `submitgmtdatetime` LIKE '&#37;$whatyear-$whatmonth%' AND `submitgmtdatetime` < '$datetocheck' ORDER BY `submitgmtdatetime` DESC") or die(mysql_error());

echo("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n");
?>
<rss version="2.0">
<channel>
<ttl>0</ttl>
<title>RSS Feed</title>
<link>http://site.com</link>
<description>RSS Feed</description>
<language>en-us</language>
<pubDate><?=gmdate("D, d M Y H:i:s \G\M\T");?></pubDate>
<lastBuildDate><?=gmdate("D, d M Y H:i:s \G\M\T");?></lastBuildDate>
<generator>OnTheFly</generator>
<image>
<title><?=$sitename;?></title>
<url>http://<?=$siteurl;?>/<? if ((gmdate("d") >= 1 && gmdate("m") == 12) || (gmdate("d") <= 4 && gmdate("m") == 1)) {?>images/xmas header.png<? } else { ?>images/header.png<? } ?></url>
<link>http://<?=$siteurl;?>?s=rssimg</link>
<width>88</width>
<height>31</height>
</image>
<?php while ($result = @mysql_fetch_assoc($resultset)) {
echo(" <item>\n");
echo(" <title><![CDATA[$result[url]]]></title>\n");
echo(" <link>http://$siteurl/?v=$result[id]&amp;h=r</link>\n");
$py = substr($result[submitteddate], 0, 4);
$pm = substr($result[submitteddate], 5, 2);
$pd = substr($result[submitteddate], 8, 2);
$ph = substr($result[submitteddate], 11, 2);
$pm = substr($result[submitteddate], 14, 2);
$ps = substr($result[submitteddate], 17, 2);
$submitteddate = gmdate("D, d M Y H:i:s GMT", gmmktime($ph, $pm, $ps, $pm, $pd, $py));
echo(" <pubDate>$submitteddate</pubDate>\n");
echo(" <description>$result[desc]</description>\n");
echo(" </item>\n\n");
} ?>
</channel>
</rss>
<?
mysql_close();
?>

bcarl314
01-05-2008, 04:32 AM
Please put your code in [ p hp ] code blocks. Thanks

jasonc310771
01-05-2008, 10:36 AM
Please put your code in [ p hp ] code blocks. Thanks
sorry to be an idiot but what is that?

this is my php code

GJay
01-05-2008, 10:36 AM
Why not store the submit-date as a timestamp in the database?

Inigoesdr
01-05-2008, 01:02 PM
sorry to be an idiot but what is that?

http://www.codingforums.com/showthread.php?t=68462



<?php
echo 'example';
?>

Becomes:

<?php
echo 'example';
?>
It's easier to read, and syntax highlighted so errors will be easier to spot. You should also indent your code to make it that much more easier to read.

the-dream
01-05-2008, 06:26 PM
<?php
header('Content-type: text/xml');
include("dbconfig.php");

// the DATE_FORMAT is to make the date RFCwhatsit compliant
$whatmonth = gmdate('m'); $whatyear = gmdate('Y'); $datetocheck = gmdate("Y-m-d H:i:s");
$resultset = mysql_query("SELECT * FROM `sites` WHERE `confirmed` = '1' AND `linklocation` = 'main' AND `submitgmtdatetime` LIKE '%$whatyear-$whatmonth%' AND `submitgmtdatetime` < '$datetocheck' ORDER BY `submitgmtdatetime` DESC") or die(mysql_error());

echo("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n");
?>
<rss version="2.0">
<channel>
<ttl>0</ttl>
<title>RSS Feed</title>
<link>http://site.com</link>
<description>RSS Feed</description>
<language>en-us</language>
<pubDate><?=gmdate("D, d M Y H:i:s \G\M\T");?></pubDate>
<lastBuildDate><?=gmdate("D, d M Y H:i:s \G\M\T");?></lastBuildDate>
<generator>OnTheFly</generator>
<image>
<title><?=$sitename;?></title>
<url>http://<?=$siteurl;?>/<? if ((gmdate("d") >= 1 && gmdate("m") == 12) || (gmdate("d") <= 4 && gmdate("m") == 1)) {?>images/xmas header.png<? } else { ?>images/header.png<? } ?></url>
<link>http://<?=$siteurl;?>?s=rssimg</link>
<width>88</width>
<height>31</height>
</image>
<?php while ($result = @mysql_fetch_assoc($resultset)) {
echo(" <item>\n");
echo(" <title><![CDATA[$result[url]]]></title>\n");
echo(" <link>http://$siteurl/?v=$result[id]&amp;h=r</link>\n");
$py = substr($result[submitteddate], 0, 4);
$pm = substr($result[submitteddate], 5, 2);
$pd = substr($result[submitteddate], 8, 2);
$ph = substr($result[submitteddate], 11, 2);
$pm = substr($result[submitteddate], 14, 2);
$ps = substr($result[submitteddate], 17, 2);
$submitteddate = gmdate("D, d M Y H:i:s GMT", gmmktime($ph, $pm, $ps, $pm, $pd, $py));
echo(" <pubDate>$submitteddate</pubDate>\n");
echo(" <description>$result[desc]</description>\n");
echo(" </item>\n\n");
} ?>
</channel>
</rss>
<?
mysql_close();
?>


There you go I did it for you!

mlseim
01-05-2008, 08:13 PM
You're grabbing string positions from a string using "substr".

Are you sure you're grabbing the correct locations for each variable?

You should echo them all out and make sure.

Other than that ... I agree with Gjay ... there must be a better
way to do this. A timestamp would be so simple.
http://us3.php.net/time



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum