RSS and MYSQL - php Form

Author Topic: RSS and MYSQL  (Read 1944 times)

Offline alex

  • Global Moderator
  • *****
  • Posts: 77
  • Karma: +19/-0
    • View Profile
RSS and MYSQL
« on: October 27, 2009, 01:54:11 PM »


Publishing MySQL Data in RSS 2.0

config.php

Code: [Select]
<?php 
$dbhost 
'localhost';
$dbusername 'root';
$dbpassword 'mydbpass';
$dbname 'test';
$conn=mysql_connect($dbhost$dbusername$dbpassword);
if(!
$conn) :
   die(
'Could not connect: ' mysql_error());
endif;
$db=mysql_select_db($dbname$conn);
if(!
$db) :
   die (
'Can\'t connect to database : ' mysql_error());
endif;
?>



rss.php


Code: [Select]
<?php header('Content-type: application/rss+xml'); ?>
<?php echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href="http://www.example.com/rss.php" rel="self" type="application/rss+xml" />
<title>example.com</title>
<description>news example.com</description>
<link>http://www.example.com</link>
<?php
include ('config.php');
$result mysql_query("SELECT id, title, description, date  FROM news ORDER by date DESC LIMIT 5"
or die(
mysql_error()); 
while(
$row mysql_fetch_array($result)){
?>

<item>
<title> <?php echo $row['title']; ?></title>
<description><?php echo htmlspecialchars($row['description'], ENT_QUOTES);?></description>
<link>http://www.example.com/?id=<?php echo $row['id']; ?></link>
<guid>http://www.example.com/<?php echo $row['id']; ?>.html</guid>
<pubDate> <?php echo date("r"strtotime($row["date"])); ?></pubDate>
</item>  
<?php 

?>
 
</channel>
</rss>
« Last Edit: October 28, 2009, 09:06:29 AM by admin »

djape

  • Guest
Re: RSS and MYSQL
« Reply #1 on: October 28, 2009, 05:29:12 PM »
Very nice. Thanks  ;D