NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page RSS Feed

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 02-06-2007, 01:11 PM THREAD STARTER               #1 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 579
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




Help! RSS Feed


Hi. I was wondering whether anybody could help me. I'm just looking for a simple script which can retrieve the last 10 results from a MySQL table and then write this as an XML file (for RSS feeds). I have read many tutorials but they all seem to over-complicate things.

Willing to donate NP$. Thanks,

miseria

UPDATE: I've found this tutorial which is brilliant. However, my XML has the extension .php. Is this a problem? (http://www.sqldumpster.com/xml.php)
Last edited by Encenta.com; 02-06-2007 at 01:55 PM.
Encenta.com is offline  
Old 02-07-2007, 05:20 AM   #2 (permalink)
Senior Member
 
netzilla's Avatar
Join Date: Aug 2005
Posts: 1,716
netzilla is a splendid one to beholdnetzilla is a splendid one to beholdnetzilla is a splendid one to beholdnetzilla is a splendid one to beholdnetzilla is a splendid one to beholdnetzilla is a splendid one to beholdnetzilla is a splendid one to beholdnetzilla is a splendid one to behold
 



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!";

?>
LOL! I didn't see the update that you found a tutorial! I would recommend renaming it to .xml just to follow the standard. I am not sure but I would think with the wrong extension it may cause problems with some feed readers.
netzilla is offline  
Old 02-10-2007, 09:37 AM THREAD STARTER               #3 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 579
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




Hi netzilla. Thanks for the script. I have donated NP$ for your help
Encenta.com is offline  
Old 02-12-2007, 05:47 AM   #4 (permalink)
Senior Member
 
netzilla's Avatar
Join Date: Aug 2005
Posts: 1,716
netzilla is a splendid one to beholdnetzilla is a splendid one to beholdnetzilla is a splendid one to beholdnetzilla is a splendid one to beholdnetzilla is a splendid one to beholdnetzilla is a splendid one to beholdnetzilla is a splendid one to beholdnetzilla is a splendid one to behold
 



Received. Thank you very much!
netzilla is offline  
Old 02-15-2007, 08:13 AM   #5 (permalink)
ccm
KICKASS
 
ccm's Avatar
Join Date: Nov 2004
Posts: 1,201
ccm is a glorious beacon of lightccm is a glorious beacon of lightccm is a glorious beacon of lightccm is a glorious beacon of lightccm is a glorious beacon of lightccm is a glorious beacon of lightccm is a glorious beacon of lightccm is a glorious beacon of light
 



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 |
ccm is offline  
Old 02-15-2007, 08:49 AM   #6 (permalink)
Senior Member
 
netzilla's Avatar
Join Date: Aug 2005
Posts: 1,716
netzilla is a splendid one to beholdnetzilla is a splendid one to beholdnetzilla is a splendid one to beholdnetzilla is a splendid one to beholdnetzilla is a splendid one to beholdnetzilla is a splendid one to beholdnetzilla is a splendid one to beholdnetzilla is a splendid one to behold
 



whatever the table name is that is holding the data that you want to put in the rss feed
netzilla is offline  
Old 02-15-2007, 09:08 AM   #7 (permalink)
NamePros Regular
Join Date: Sep 2006
Location: Germany
Posts: 387
McDot is a jewel in the roughMcDot is a jewel in the roughMcDot is a jewel in the rough
 



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
McDot is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:19 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger