Hello, I was just wondering how it is possible to have a RSS feed from my database for the last 20 videos that have been added to the site. I can't understand how i can use the RSS page and use PHP to grab the info, i can do the RSS page manually but as soon as i put php in i get errors cos its a .rss file extension. Would be greatfull for any help Olli460
If you are using Apache as your webserver, you could use a .htaccess to force it to parse .rss as .php. .htaccess AddType application/x-httpd-php .rss Code (markup):
Magpie will read an RSS file and convert it to html if it is properly coded. But is that what you want to do? Why not query the DB using php and simply get the html version of the last 20 then you either could find or buy a script to convert it to RSS so that other can read it. Or continue to code it by hand. Maybe I misunderstood what you are trying to do.
you can try something like: domain.com/rss/top_20/ and then .htaccess to redirect requests to the php file
I personally would recommend saving the rss to a xml file. If you think about if one person subribes to your rss then they will hit your site every few minutes. With every hit you're going to the database to retrieve the data even if it hasn't changed. If you times by 1,000 subscribers your server will slow down with unnecessary requests.
So how do other sites with a rss feed get the php to load into a rss page. Im currently using an XML page but it dosent look nice lol.
They vary where some where some are dynamic and some use xml files. I'm pretty anal about efficiency. Getting data from the database is pretty expensive especially if the data doesn't change. Here is my code that I use for TopMediaScript. You can use this to write to one file. Let me know if something doesn't make sense and I'll can explain it. // Open the rss file for writing if (!$xmlfile = fopen("allmediafeed.xml", "w")) { if ($rss_to_output = true) { echo "Could not open allmediafeed.xml for writing.<br /><br />"; } $tms->site_adminalerts(0, "Could not open allmediafeed.xml for writing.", "rss"); exit; } // Write the header fwrite($xmlfile, "<rss version=\"2.0\"> <channel> <title>{$tms->settings->sitetitle}</title> <link>{$tms->paths->tms_url}{$tms->paths->tms_subfolderuri}</link> <description>{$tms->settings->sitedescription}</description> <pubDate>".date("D, d M Y H:i:s O")."</pubDate> <generator>http://www.topmediascript.com</generator> <language>en</language>"); foreach ($media_queue["mediaobjects"] as $media) { // Ignore All adult media if ($media->category->is_adult == false) { $progressmsg .= "<br />Processing: id={$media->id} title={$media->title}"; $media->title = $tms->strip_html($media->title); $media->description = $tms->strip_html($media->description); fwrite($xmlfile, "<item> <title>{$media->title}</title> <link>{$tms->paths->tms_url}{$media->uri}</link> <pubDate>{$media->submitdate}</pubDate> <guid>{$media->id}</guid> <description>{$media->description}</description> </item> "); } } fwrite($xmlfile, "</channel> </rss>"); fclose($xmlfile); if ($rss_to_output == true) { echo $progressmsg; if ($msg != "") { echo "<br /><br />The following errors occurred:<br />"; echo $msg; } } PHP: The xml file looks like this: <rss version="2.0"> <channel> <title>TopMediaScript.com - The ultimate multimedia site script</title> <link>http://localhost/tms4/</link> <description>The ultimate media site script for the webmasters wanting to run their own media web site.</description> <pubDate>Fri, 19 Dec 2008 11:39:43 -0700</pubDate> <generator>http://www.topmediascript.com</generator> <language>en</language><item> <title>Test</title> <link>http://localhost/tms4/mediaviewer/5655/test.html</link> <pubDate>2008-12-19 11:34:38</pubDate> <guid>5655</guid> <description>Test</description> </item> <item> <title>Redneck Shoot-Out</title> <link>http://localhost/tms4/mediaviewer/5654/redneck-shoot-out.html</link> <pubDate>2008-12-12 11:34:34</pubDate> <guid>5654</guid> <description>Eliminate all redneck by shooting them. Complete 3 levels of difficulty to win the game.</description> </item> <item> <title>Flash Chess 3D</title> <link>http://localhost/tms4/mediaviewer/5653/flash-chess-3d.html</link> <pubDate>2008-12-12 11:34:34</pubDate> <guid>5653</guid> <description>3D Flash Chess with great AI opponent</description> </item> </channel> </rss> Code (markup):
I forgot to mention that you can setup a cron job to run at certain times to regenerate the rss or code it in your script to run when are a new item added to your site.
Hey, Thanks for posting that code but i don't really know where to start. I can get an XML file with these tags <video_title> <video_description> <video_url> <video_thumb> but how can i get these to go inside a normal looking rss page rather then the XML page thanks in advance