Be a Supporter!
<deleted>
Php: Rss 2006-06-03 18:22:13 Reply

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.

elbekko
elbekko
  • Member since: Jul. 23, 2004
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to Php: Rss 2006-06-04 07:21:14 Reply

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
JeremysFilms
JeremysFilms
  • Member since: Feb. 18, 2005
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to Php: Rss 2006-06-04 10:52:09 Reply

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

NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Php: Rss 2006-06-04 11:46:53 Reply

Thank you!

Cheesemold
Cheesemold
  • Member since: Mar. 16, 2001
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to Php: Rss 2006-06-04 12:34:38 Reply

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.

elbekko
elbekko
  • Member since: Jul. 23, 2004
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to Php: Rss 2006-06-04 13:19:44 Reply

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
NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Php: Rss 2006-06-04 15:50:12 Reply

Done

NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to Php: Rss 2006-06-04 15:58:43 Reply

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).

<deleted>
Response to Php: Rss 2006-06-04 18:00:30 Reply

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

Oh woops