Solved

RSS feed not showing item time

Posted on 2011-03-20
3
25 Views
Last Modified: 2016-05-10
The time displays on RSS feed items is not correct, it is not  the time when the item was created and saved in database. Can you please tell me that how I can correct it. Please see the code bellow. You can see the result here: http://khatesabz.info/rss.php

<?php
echo '<?xml version="1.0" ?>';
echo '<rss version="2.0">';
echo '<channel>';
echo '<title>RSS Feed</title>';
echo '<link>http://--.info</link>';
echo '<language>fa</language>';
echo '<description>" &#1582;&#1591; &#1587;&#1576;&#1586; "</description>';

require_once 'kamen/serverdata.php';
$conn = mysql_connect("$dbHost","$dbUser","$dbPass");
mysql_query('SET NAMES utf8');
$db = mysql_select_db("$dbName");
mysql_query("SET CHARACTER_SET_RESULTS=NULL");
$sql = "SELECT * FROM lastnews ORDER BY id DESC LIMIT 15";
$result = mysql_query($sql);
while($row=mysql_fetch_assoc($result)){
echo '<item>';
echo '<pubDate>'.$row['date'].'</pubDate>';
echo '<pubTime>'.$row['time'].'</pubTime>';
echo '<title>'.$row['title'].'</title>';
echo '<link>'.$row['code'].'</link>';
echo '<description>'.$row['description'].'</description>';
echo '</item>';
}
echo '</channel>';
echo '</rss>';
?>
0
Comment
Question by:sam20
3 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 35177261
RSS is a specialized subset of XML.  You can find more information on RSS here.  A quick search of that page will show you that there is no "pubTime" tag defined.
http://cyber.law.harvard.edu/rss/rss.html

The correct format for the RSS pubDate is RFC822 or RFC 2822.  In PHP this is date('r') format.  I think your problem arises from providing the wrong format for pubDate.  Check these links.
http://asg.web.cmu.edu/rfc/rfc822.html
http://php.net/manual/en/function.date.php

I would also like to suggest that the use of MySQL reserved words like "date" and "time" for column names is a recipe for confusion.  Here is an article that shows a little more about how to handle date and time in PHP and MySQL.  See if it helps you sort out the information that you have to store in the data base and reproduce in the XML of the RSS feed.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

An object-oriented version of the article is available here.
https://www.experts-exchange.com/articles/20920/Handling-Time-and-Date-in-PHP-and-MySQL-OOP-Version.html

HTH, ~Ray
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question