Solved

RSS feed not showing item time

Posted on 2011-03-20
3
16 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 108

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
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 …

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now