Saturday, 21 September 2013

Create RSS Feed with PHP Mysql

RSS feed is playing main role for syndicating information to large audiences. By this feed you can update your audience with your latest content or information. RSS feed means that if you have some number of registered audiences then you can share your new updates and news directly to your audience on their registered e-mails ID.
In this tutorial I will explain how to populate your database content to RSS feed. Here in RSS feed we will display some useful content like title, description, date and image etc. For this we will use PHP and mysql to populate content for RSS feed. Here we will retrieve this content from database and format these content into RSS format.
Steps are given below: Create table for getting data for RSS Feed
1
2
3
4
5
6
7
8
9
10
11
CREATE TABLE IF NOT EXISTS `table_rss` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` text NOT NULL,
  `description` text NOT NULL,
  `url` text NOT NULL,
  `image` varchar(255) NOT NULL,
  `created_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `modified_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `status` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=35 ;
Create a php like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!--?php
define ("DB_HOST", "localhost"); // set database host
define ("DB_USER", ""); // set database user
define ("DB_PASS",""); // set database password
define ("DB_NAME",""); // set database name
  
$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
$db = mysql_select_db(DB_NAME, $link) or die("Couldn't select database");
$query = "SELECT title, description, image, url FROM ".table_rss." WHERE status=1 ORDER BY created_date desc";
$getBlogDisplay = mysql_query($query);
header("Content-type: text/xml");
echo "<?xml version='1.0' encoding='UTF-8'?-->
<rss version="2.0">
<channel>
<title></title>
<link>
<description></description>
<language>en-us</language>";
while($dataBlogDisplay = mysql_fetch_array($getBlogDisplay)){
           
 $title         = $dataBlogDisplay['title'];
 $link          = $dataBlogDisplay['url'];
$description    = $dataBlogDisplay['image'];
echo "<item>
<title>$title</title>
<link>http://www.discussdesk.com/$link.htm
<description>$description</description>
</item>";
}
echo "</channel></rss>";
?>
That's all about RSS Feed. Just download and start feeding your content.
Read More : http://www.discussdesk.com/create-rss-feed-with-php-mysql.htm

No comments:

Post a Comment