00:00
00:00
Newgrounds Background Image Theme

kyzakay just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Php: Rss 2006-06-03 18:22:13


PHP: main

elbekko wanted this so here it is:


rss.php
<?
header("Content-type: text/xml"); //Set the header to XML.

$data = mysql_connect("localhost", "username", "password");
mysql_select_db ("RSSdb"); //Connect to your database.
?>

<rss version="2.0">
<channel>
<title>News</title> // Your RSS title
<description>Latest News</description> // Description of RSS
<link>http://www.yoursite.com</link> // And link to your website.

<?
$query = "SELECT * FROM news ORDER BY id DESC LIMIT 5";//Orders 5 news posts by post id.
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)){ //Set up a while loop
?>

<item>
<title><?=$row['title']; ?></title>
<author><?=$row['author']; ?></author>
<link>http://www.yoursite.com/viewNews.php
?id=
<?=$row['id']; ?></link>
</item>

<?
}
echo '</channel>\n</rss>';
mysql_close($data);
?>

Now we include the RSS on your page with this code:

<link rel="alternate" type="application/rss+xml" title="News" href="http://www.yoursite.com/rss.php" />

RSS is pretty simple and easy to get the hang of once you grasp the concepts of XML.

Response to Php: Rss 2006-06-04 07:21:14


Huh? Did I ask for this? =/ That's a new one, I made my own RSS script a loooooong time ago :p


"My software never has bugs. It just develops random features. " - Unknown

[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]

BBS Signature

Response to Php: Rss 2006-06-04 10:52:09


You kind of just gave a commented code instead of explaining everything...

Response to Php: Rss 2006-06-04 11:46:53


Thank you!

Response to Php: Rss 2006-06-04 12:34:38


At 6/4/06 10:52 AM, JeremysFilms wrote: You kind of just gave a commented code instead of explaining everything...

Well, I learned something.

Response to Php: Rss 2006-06-04 13:19:44


A little comment: this will NOT work on hosts who have short tags disabled.


"My software never has bugs. It just develops random features. " - Unknown

[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]

BBS Signature

Response to Php: Rss 2006-06-04 15:50:12


Response to Php: Rss 2006-06-04 15:58:43


A bug in the last lines:

It goes:

echo "</channel>\n</rss>";

Not:

echo '</channel>\n</rss>';

Since single quotes won't convert \n (newlines).

Response to Php: Rss 2006-06-04 18:00:30


At 6/4/06 03:58 PM, Nino_JoJ wrote: A bug in the last lines:

Oh woops