Jump to content

Php Rss


ckrudelux
 Share

Recommended Posts

Okay I'm doing a rss file by using php and a db.

<?php header('Content-type: text/xml'); ?><rss version="2.0"><channel>	<title>YourNews</title>	<description>Your own news paper</description>	<link>http://webaddress.com</link><?phpmysql_pconnect('localhost', 'Username', 'Password') or die("Can not connect");			mysql_select_db("yournews");		$query = mysql_query("SELECT * FROM articles WHERE categorys='musicvideos' ORDER BY article_id DESC LIMIT 5");				while($row = mysql_fetch_assoc($query)){?><item>	 <title><?php echo $row['categorys'];?></title>	 <pubDate><?php echo $row['post_date'];?> <?php echo $row['post_time'];?> CET</pubDate>	 <author><?php echo $row['name'];?></author>	 <description><?php echo $row['headline'];?></description>	 <link>http://webaddress.com/<?php echo $row['categorys'];?></link></item><?php}?></channel></rss>

This is my problem right now I get a time in the rss for 01:00 so this means that it couldn't write out the time that stands in my db.Anyone knows why? could it be becouse of the length of the time "00:00:00" in the rss it only shows "00:00"anyway help !

Link to comment
Share on other sites

If there's a value in the post_time field, then it will write it out. If it's writing "01:00" when you tell it to write post_time, then post_time contains "01:00". The code isn't telling it to do anything else.
Well I got help with it... The problem is that xml is very strict and my php writes the time in the wrong format. :) in rss code you are not allowed to write the date/time like this 00-00-00 00:00:00.The correct why is to wirte it "Fri, 18 Nov 2009 19:12:30" if it's not like this you will get like in my case of code... the date correct and a time for 01:00 even if you only write the date you will get the time set too 01:00.Thanks anyway
Link to comment
Share on other sites

Well I got help with it... The problem is that xml is very strict and my php writes the time in the wrong format.
OK, then you were probably mistaken here:
This is my problem right now I get a time in the rss for 01:00 so this means that it couldn't write out the time that stands in my db.
It sounds like you were checking the RSS using an RSS reader. You should have just opened up the RSS code in a text editor. You would have seen that PHP was printing the entire date, but the RSS reader was displaying something else. When you're debugging stuff like this it's always best to look at exactly what PHP is producing, not necessarily what something else is doing with the output. If you just look at a rendered version you may assign the blame to the wrong thing (you blamed PHP for not writing what was in the database when that wasn't the problem).
Link to comment
Share on other sites

OK, then you were probably mistaken here:It sounds like you were checking the RSS using an RSS reader. You should have just opened up the RSS code in a text editor. You would have seen that PHP was printing the entire date, but the RSS reader was displaying something else. When you're debugging stuff like this it's always best to look at exactly what PHP is producing, not necessarily what something else is doing with the output. If you just look at a rendered version you may assign the blame to the wrong thing (you blamed PHP for not writing what was in the database when that wasn't the problem).
Okay then I see I wasen't clear enough the php is wirting the right stuff from the database but the rss reader can't read the daye/time format that is in my database.So I need to change the format of the time date print :)
Link to comment
Share on other sites

Yeah, the date function will do that.http://www.php.net/manual/en/function.date.phpIf you need a date in this format:Fri, 18 Nov 2009 19:12:30It would be like this:date('D, j M Y H:i:s', $timestamp);If you need to create a timestamp to use for that function from a date in your database, you can use strtotime:http://www.php.net/manual/en/function.strtotime.phpe.g.

$timestamp = strtotime('2009-05-31 12:00:00');echo date('D, j M Y H:i:s', $timestamp);

Link to comment
Share on other sites

Yeah, the date function will do that.http://www.php.net/manual/en/function.date.phpIf you need a date in this format:Fri, 18 Nov 2009 19:12:30It would be like this:date('D, j M Y H:i:s', $timestamp);If you need to create a timestamp to use for that function from a date in your database, you can use strtotime:http://www.php.net/manual/en/function.strtotime.phpe.g.
$timestamp = strtotime('2009-05-31 12:00:00');echo date('D, j M Y H:i:s', $timestamp);

Okay thanks mange to get the code working :)here is the working code line
<pubDate><?php echo date('D, j M Y', strtotime($row['post_date']));?> <?php echo $row['post_time']; ?> +0100</pubDate>

:) Well only one thing left to fix on this page I'm building.Does anyone know the code for the header to move you back to the previous page??

Link to comment
Share on other sites

There's not a header to go back. In most situations the referer header that the browser sends is the page they were just at though, but not all situations.
if ($_SERVER['HTTP_REFERER'] != ''){  header('Location: ' . $_SERVER['HTTP_REFERER']);  exit();}

Thanks for the code.. and help :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...