| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| SQLdumpster.com Join Date: Jun 2005 Location: West Sussex, UK
Posts: 579
![]() ![]() | |
| |
| | #2 (permalink) |
| Senior Member Join Date: Aug 2005
Posts: 1,716
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | This is a script that I wrote to perform the same function for my website. If you have any questions feel free to ask. Enjoy! Note: You will need to change a few things in order for it to work on your website. (i.e. database, username, password, and tablename.) The database table that I used was setup with the fields id, title, description, and link so you may need to make a few adjustments to fit your table. Code: <?php
// Establishes db connection
$database = "database";
$username = "username";
$password = "password";
mysql_connect("localhost", $username, $password) || die ("Unable to select database");
mysql_select_db($database);
//Path and name to save xml file
$output = "feeds/feed.xml";
//Opens output file for writing
$open = fopen($output, "w+");
//Writes standard tags output file
fwrite($open, "<?xml version=\"1.0\" ?>\n");
fwrite($open, "<rss version=\"2.0\">\n");
fwrite($open, "<channel>\n");
fwrite($open, "<title>Enter site title here</title>\n");
fwrite($open, "<description>Enter description of your site there</description>\n");
fwrite($open, "<link>http://www.yoursite.com</link>\n");
// Grabs last 10 records
$query = "SELECT * FROM tablename ORDER BY id DESC LIMIT 10";
$result = mysql_query($query);
$num = mysql_num_rows($result);
$i = 0;
while ($i < $num) {
$title = mysql_result($result,$i,"title");
$desc = mysql_result($result,$i,"description");
$link = mysql_result($result,$i,"link");
fwrite($open, "<item>\n");
fwrite($open, "<title>" . $title . "</title>\n");
fwrite($open, "<description>" . $desc . "</description>\n");
fwrite($open, "<link>" . $link . "</link>\n");
fwrite($open, "</item>\n");
$i++;
}
// Writes standard closing tags
fwrite($open, "</channel>\n");
fwrite($open, "</rss>");
//Closes output file
$close = fclose($open);
echo "RSS feed generated!";
?> |
| |
| | THREAD STARTER #3 (permalink) |
| SQLdumpster.com Join Date: Jun 2005 Location: West Sussex, UK
Posts: 579
![]() ![]() | Hi netzilla. Thanks for the script. I have donated NP$ for your help
__________________ SQL Dumpster - SQL Database Dumps and Resources |
| |
| | #5 (permalink) |
| KICKASS Join Date: Nov 2004
Posts: 1,201
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | cool! but what would you cahnge the "tablename" to?
__________________ fishtail.net | Spouty.com | LumbarSpine.net | kingfish.org | tightlines.org | z-z.org newcellphone.org |MacNugget.com| EZPG.com | TheeBomb.com SportFisher.net | |
| |
| | #7 (permalink) |
| NamePros Regular Join Date: Sep 2006 Location: Germany
Posts: 387
![]() ![]() ![]() | Interesting script. I'll give it a try as soon as I find some time. Thanks for sharing.
__________________ My Domain Blog - German Webdesign Forum Spanish Domaincenter: Villa Dominio Domains for sale: SoSay.com - SocialLinkbuilding.com - SEOTechnician.com - Favorizer.com Spanish Domains: Aspiradoras.es - Tarantula.es - Chikas.es - Buey.es - Besitos.es |
| |