Hello I am looking to create some RSS feeds for my sites. More particular I am interested in how to write to RSS file from a PHP Mysql Query I imagine it would be something like: $qr = mysql_query("SELECT * FROM table WHERE something = thisorthat LIMIT10); while( $row = mysql_fetch_object($qr) ){ write.to some.rss (<title>$row->title</title>... etc for <desc> ...) } PHP: If you know of any good tool or tutorial or simply could give me some code I would highly appreciate it. Thanks in advance
Look up PHP scripts that do this or look at existing RSS documents and mimick their format. There's nothing to it (I've done it a few times). Just dissect the RSS format and print it out with your code.
It is simple to write a RSS file Do you know the default RSS format? If not, let me know, I'll base my next reply on that
You see for more info just go to wikipedia and search for RSS there you have all the infor you'd need
<? header('Content-Type: application/xhtml+xml; charset=utf-8'); $query=mysql_query("SELECT * from table WHERE something = thisorthat LIMIT10"); $body="<?xml version=\"1.0\" encoding=\"utf-8\"?> <rss version=\"2.0\"> <channel> <title>SistemBilgisi</title> <link>http://www.sistembilgisi.com</link> <description>SistemBilgisi</description> <copyright>(c) 2005,SistemBilgisi</copyright> "; while($r = mysql_fetch_array($query)) { $body .=" <item> <title>".$r[name]."</title> <link>http://www.sistembilgisi.com/".$r['id'].".html</link> //you are design the line for your links <description>".$r[text]."</description> <pubDate>$r[date]</pubDate> </item>"; } $body .=" </channel> </rss>"; echo $body; /* $path="rss.xml"; $filenum=fopen($path,"w"); fwrite($filenum,$body); fclose($filenum); */ ?> PHP:
Thank you very much, I also often see images in the rss feeds, but when you add <image></image> tags to the channel it does not go through in the validator, should I just insert images into description?
Yepp and use the regular <img> tag instead. Have a look at the Wikipedia entry on RSS ( http://en.wikipedia.org/wiki/RSS#Example_-_RSS_2.0 ).
Lets just say I dont know the default, (because I have to merge several sql fields to make the different rss fields) how would you go about this?