First of all here it is the source that is going to be shown as plain text
<?xml version="1.0" encoding="ISO-8859-1" ?>If you don't know how to use phpmyadmin please read how to post to database
<rss version="2.0">
<channel>
<title>Rss feeds on php and mysql</title>
<link>http://www.thecodertips.com</link>
<description>Web developement tutorials</description>
<item>
<title>Using blogger tags to beautify template and creating plugins</title>
<link>http://www.thecodertips.com/2013/03/using-blogger-tags-to-beautify-template.html</link>
<description>Blogger tips</description>
</item>
<item>
<title>Php tutorial, Login script with Jquery</title>
<link>http://www.thecodertips.com/2012/11/php-tutorial-login-script-with-jquery.html</link>
<description>Php script</description>
</item>
</channel>
</rss>
So to explain
This is what we are going to build
// site title
// link
// description
*** post 1 ***
// title
// link
// description
*** post 2 ***
// title
// link
// description
// end Go to phpmyadmin, create a new table, name it 'posts' and create the fields:
id (int, auto increment)
title (text)
link (text)
description (text) Save it and then go to insert(phhmyadmin), and write 2 new posts, fill in all the fields except id.
Now create a php file called config.php, this file makes connection to database
<?phpNow create another php file, name it for ex rss.php
mysql_connect("localhost", "root", "") or die("could not connect"); // host, user, password
mysql_select_db("database") or die("could not select database"); // database name
?>
<?phpYou are done, for better preview view the php file in mozilla firefox, you can also use mod rewrite to change extension form .php to .xml or .rss
header("Content-Type: application/xml; charset=ISO-8859-1");
include("config.php");
?>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">
<channel>
<title>Rss feeds on php and mysql</title>
<link>http://www.thecodertips.com</link>
<description>Web developement tutorials</description>
<?php
$query = mysql_query("SELECT title, link, description FROM posts");
while($row = mysql_fetch_array($query)){
echo '<item>
<title>'.$row['title'].'</title>
<link>'.$row['link'].'</link>
<description>'.$row['description'].'</description>
</item>';
}
echo '
</channel></rss>';
?>
Edit! I forgot adding the header to rss.php so just paste this code in line 2
header("Content-Type: application/xml; charset=ISO-8859-1");
its not working
ReplyDeletePlease check out here. This code is working
Deletehttp://www.discussdesk.com/create-rss-feed-with-php-mysql.htm
its working
ReplyDeleteXML Parsing Error: XML or text declaration not at start of entity
ReplyDeleteGood tuto, this is another one with source code:
ReplyDeletehttp://www.bewebdeveloper.com/tutorial-about-how-to-create-an-rss-feed-with-php-and-mysql
What should be the mime type for the result?
ReplyDelete