Skip to main content

Generate RSS Feed with PHP & MySQL

RSS (Really Simple Syndication) is a very useful way to share content over internet. If you are running a website or blog RSS feeds can help you a lot by sharing your contents to readers. RSS feeds are based on XML markup. It holds some information about your post contents like post title, description, link, publish date etc.

In this post you will learn how we can create simple RSS feed with PHP and MySQL.

Creating MySQL Database Table

At first we need to create a database table that can hold our post contents.

CREATE TABLE `post` (
  `id` int(6) NOT NULL AUTO_INCREMENT,
  `title` varchar(128) NOT NULL,
  `body` text NOT NULL,
  PRIMARY KEY (`id`)
);

PHP Code

# configurations
$db_host = 'localhost';
$db_user = 'root';
$db_pass = 'root';
$db_name = 'test';
$max_post_limit = 10;


# set content type application/rss+xml
header("Content-Type: application/rss+xml; charset=UTF-8");

# connect to mysql db
mysql_connect($db_host, $db_user, $db_pass);
# select mysql db
mysql_select_db($db_name);

# query in db table
$query = mysql_query(
  'SELECT *
  FROM post
  ORDER BY id DESC
  LIMIT ' . $max_post_limit
);

?>
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

  <channel>

    <title>My RSS Feed</title>
    <description>w3bees RSS Feed</description>
    <link>http://www.w3bees.com</link>
    <language>en-us</language>
    <copyright>Copyright (C) 2013 w3bees.com</copyright>

  <?php while( $row = mysql_fetch_array($query) ): ?>

    <item>
      <title><?php echo $row['title']?></title>
      <description><?php echo $row['body']?></description>
      <link>http://mysite.com/post.php?id=<?php echo $row['id']?></link>
    </item>

  <?php endwhile?>

  </channel>
</rss>

Comments

  1. Nếu như còn gặp lại.
    Ta sẽ nói những gì
    Lẽ nào nhìn vào mắt
    dịch vụ kế toán trọn gói quận 3
    dịch vụ kế toán trọn gói quận 2
    dịch vụ kế toán thuế trọn gói tại tp hcm
    Trước đây thất thì cảm thấy khủng khiếp lắm
    Giờ còn thất nhiều hơn mà sao vẫn thấy vui vẻ thế

    ReplyDelete
  2. Buông ra! – Hân cố giằng tay ra khỏi Bảo.
    – Nhìn thấy tôi tại sao lại chạy? – Bảo hỏi, bàn tay siết chặt hơn lấy cổ tay Hân. Tiếng anh cho người đi làm
    Tiếng anh cấp tốc
    Luyện thi toeic tại hà nội
    Tiếng anh cho người lớn tuổi
    Tiếng anh cho người mới bắt đầu
    Học tiếng anh tại hà nội
    dạy tiếng anh cho doanh nghiệp
    – Mặc kệ tôi! – Hân vẫn cố giằng ra, sức mạnh của Bảo khiến Hân cảm giác như cổ tay mình bị vỡ vụn, vô thức, cô nhăn mặt. – Đau…

    ReplyDelete
  3. The info Shared is very much useful Thanks for sharing it
    Hadoop Training in Chennai

    ReplyDelete
  4. hi welcome to this blog. really you have post an informative blog. it will be really helpful to many peoples. thank you for sharing this blog.
    python training in chennai

    ReplyDelete
  5. really you have been shared very informative blog. it will be really helpful to many peoples. so keep on sharing such kind of an interesting blog.
    hadoop training in chennai

    ReplyDelete
  6. Very good informative article. Thanks for sharing such nice article, keep on up dating such good articles.

    BEST MOBILE APPLICATION DEVELOPMENT SERVICES | MASSIL TECHNOLOGIES

    ReplyDelete
  7. Try to use the Dịch Vụ Làm Visa Trọn Gói Hà Nội Viseca offers a wide selection of Mastercard and Visa credit cards. Read more online now and make a free comparison.

    ReplyDelete
  8. Amazing Article ! I have bookmarked this article page as i received good information from this. All the best for the upcoming articles. I will be waiting for your new articles. Thank You ! Kindly Visit Us @ Coimbatore Travels | Ooty Travels | Coimbatore Airport Taxi

    ReplyDelete
  9. Amazing article. Your blog helped me to improve myself in many ways thanks for sharing this kind of wonderful informative blogs in live. I have bookmarked more article from this website. Such a nice blog you are providing ! Kindly Visit Us @ Best Travels in Madurai | Tours and Travels in Madurai | Madurai Travels

    ReplyDelete

Post a Comment

Popular posts from this blog

Multiple File Upload with PHP

Sometimes we need to allow our users to upload multiple file upload. On my previous post I was shown the basic of simple file upload with PHP. Today I am going to show you how to allow users to upload multiple files. It is almost similar like simple file upload but we need to do some modification with html markup and php code. multiple attribute is needed to add on the html markup. Major web browsers like Firefox, Chrome, Safari and IE 9+ support this attribute. Now I am going to show you how to upload multiple file with PHP and basic HTML form.

Live Comment System with jQuery Ajax PHP and MySQL

Recently I have been made a post that focused on how to submit form without page refreshing. That post shows the basic functionality of using jQuery Ajax. On the same follow this post will describe how we can create a comment system to post an instant comment without page refreshing. Let's start...

Resize Image While Uploading with PHP

On my previous post I was shown an example how to upload file with php and html. It was based on php simple image upload functionality. Today I am going to show you little bit advance of image uploading. Suppose if you run a website and want to allow users to upload image files than you need to think little bit about server's space and bandwidth. For this purpose you need to do some optimization with image files. Image resize while uploading is one of them. All major website do it in the same way. If a user uploads a 5mb image file they resize it in different sizes and store on there server. It helps them to seed up there website and reduce there budget. Now take a look, how we can do it ourself.