generating rss files from php

Soldato
Joined
1 Feb 2006
Posts
8,188
hi, as title suggests I am trying to output content from webforms into a mysql database and at the same time export the data to an RSS feed. The problem is that I will have a number of separate feeds that may require this content. I cannot get my head around the process of checking every file and either adding or ignoring that particular file. I have a number of categories such as General, Topical, Off topic sections each with a separate feed. If two checkboxed are ticked that means that the form data should be added to two files. Anyone have any ideas how I can do this? I don't even know how to create files in php yet nevermind export content to them but it is something il need to get sorted over the weekend. Thanks in advance!
 
there is no issue with using php and passing in variables to generate rss on the fly, so long as you take the timestamp for the items from the database.
 
Rather than write, generate and, if necessary, cache. For example, feed.topical.php:
Code:
SELECT `blah` FROM `tbl` WHERE `cat` = 'topical';
etc.?
 
Cache the RSS feed.

Code:
<?php

	include 'db.php';

	$sql = mysql_query("SELECT * FROM `rss` ORDER BY `id` DESC LIMIT 0, 15");

	$xml = "<?xml version=\"1.0\"?>
	<rss version=\"2.0\">
		<channel>
			<title>Title of Feed</title>
			<description>Decription of Feed</description>
			<link>Http://www.linktowebsite.com</link>";	

	while($result = mysql_fetch_array($sql)){
	$title = $result['title'];
	$description = $result['description'];
	$link = $result['link'];
	$xml .= "
		<item>
			<title>$title</title>
			<description>$description</description>
			<link>$link</link>
		</item>";
	}

	$xml .= "
		</channel>
	</rss>";

	$file = fopen("index.xml", 'w+') or die("can't open file");
	fwrite($file, $xml);
	fclose($file);

	echo 'RSS Feed Updated';

?>
 
Conrad11 said:
Cache the RSS feed.

Code:
<?php

	include 'db.php';

	$sql = mysql_query("SELECT * FROM `rss` ORDER BY `id` DESC LIMIT 0, 15");

	$xml = "<?xml version=\"1.0\"?>
	<rss version=\"2.0\">
		<channel>
			<title>Title of Feed</title>
			<description>Decription of Feed</description>
			<link>Http://www.linktowebsite.com</link>";	

	while($result = mysql_fetch_array($sql)){
	$title = $result['title'];
	$description = $result['description'];
	$link = $result['link'];
	$xml .= "
		<item>
			<title>$title</title>
			<description>$description</description>
			<link>$link</link>
		</item>";
	}

	$xml .= "
		</channel>
	</rss>";

	$file = fopen("index.xml", 'w+') or die("can't open file");
	fwrite($file, $xml);
	fclose($file);

	echo 'RSS Feed Updated';

?>

cheers for that i think that will partially solve my problem. How would I go about writing to multiple files though?
 
Back
Top Bottom