Jump to content

Rss Feeds and pubDate


dropfaith

Recommended Posts

So im working with rss and basicly im wondering what the best way to get and store the pubdate is.im assuming timestamp with a null of the current time is right but im just check also some pointers on getting the current time would be awesome for inserting into mysql.

full code to display rss is below not sure why you would need it but meh

<?php header('Content-type: text/xml'); ?>
<rss version="2.0">
<channel>
<title>Dropfaith Productions</title>
<description>Rss Feed</description>
<link>http://dropfaithproductions.com/layout/index.php</link>
<copyright> http://dropfaithproductions.com/layout/index.php</copyright>
<webmaster>dropfaith Productions</webmaster>
<managingEditor>Matt Foley</managingEditor>
<?php
// includes
include("template/conf.php");
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
$q="SELECT * FROM news ORDER BY Id DESC";
$doGet=mysql_query($q);
while($result = mysql_fetch_array($doGet)){
?>
     <item>
        <title><?=htmlentities(strip_tags($result['Title']));?></title>
        <description><?=htmlentities(strip_tags($result['News'],'ENT_QUOTES'));?></description>
        <link>http://dropfaithproductions.com/layout/permalink.php?Id=<?=$result['Id'];?></link>	
        <pubDate><?=htmlentities(strip_tags($result['Date']));?></pubDate>
     </item>  
<?php } ?>  
</channel>
</rss>

Link to comment
https://forums.phpfreaks.com/topic/125166-rss-feeds-and-pubdate/
Share on other sites

The first thing I recommend is get rid of these <?= , if you port this code to a server that does not have short open tags set to on, then your code will fail. It is good coding practice to use <?php echo instead.

 

As for the date, you can do a couple things. When you insert the row in the DB, you can use time() to get the current timestamp.

 

Alternatively you can let mysql handle it. Set the data type for that row to timestamp and set the attributes to be on update current_timestamp.

 

How are you setting the time field now?

 

Nate

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.