Search for:
Jump to: 
Your Ad Here
Post new topic Reply to topic
Author Message
 Post subject: How to create rss feed using mysql and php?
PostPosted: Thu Jul 30, 2009 5:45 am 
Offline

Joined: Mon Feb 02, 2009 11:15 am
Posts: 52
Hi,

Can anyone help me on how to create rss feed using php and mysql.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 30, 2009 5:56 am 
Offline

Joined: Fri May 09, 2008 4:10 am
Posts: 229
Hello,

the following code will generate the rss feed using php and mysql.

In the classes folder :

rss.class.php file

<?

class RSS
{
public function RSS()
{
require_once ('mysql_connect.php');
}

public function GetFeed()
{
return $this->getDetails() . $this->getItems();
}

private function dbConnect()
{
DEFINE ('LINK', mysql_connect (DB_HOST, DB_USER, DB_PASSWORD));
}

private function getDetails()
{
$detailsTable = "webref_rss_details";
$this->dbConnect($detailsTable);
$query = "SELECT * FROM ". $detailsTable;
$result = mysql_db_query (DB_NAME, $query, LINK);

while($row = mysql_fetch_array($result))
{
$details = '<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">
<channel>
<title>'. $row['title'] .'</title>
<link>'. $row['link'] .'</link>
<description>'. $row['description'] .'</description>
<language>'. $row['language'] .'</language>
<image>
<title>'. $row['image_title'] .'</title>
<url>'. $row['image_url'] .'</url>
<link>'. $row['image_link'] .'</link>
<width>'. $row['image_width'] .'</width>
<height>'. $row['image_height'] .'</height>
</image>';
}
return $details;
}

private function getItems()
{
$itemsTable = "webref_rss_items";
$this->dbConnect($itemsTable);
$query = "SELECT * FROM ". $itemsTable;
$result = mysql_db_query (DB_NAME, $query, LINK);
$items = '';
while($row = mysql_fetch_array($result))
{
$items .= '<item>
<title>'. $row["title"] .'</title>
<link>'. $row["link"] .'</link>
<description><![CDATA['. $row["description"] .']]></description>
</item>';
}
$items .= '</channel>
</rss>';
return $items;
}

}

?>

In the mysql.php file

<?
DEFINE ('DB_USER', 'root');
DEFINE ('DB_PASSWORD', 'root');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'rss');

// Make the connnection and then select the database.
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );
mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() );
?>


In the php file:

<?
header("Content-Type: application/xml; charset=ISO-8859-1");
include("classes/RSS.class.php");
$rss = new RSS();
echo $rss->GetFeed();
?>

Hope that it will be useful.

Thank you,

Anil Kumar :P :P :P


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic    [ 2 posts ] 

1, 2, 3, 4, 5 ... 414
Recent topics  Replies   Views   Last post 
No new posts Add Slide Notes & Images as Logos in MS PowerPoint

by aspose » Tue May 21, 2013 4:03 am in Miscellaneous

0

7

Tue May 21, 2013 4:03 am

aspose View the latest post

No new posts Jquery ajax Pagination using php

by rajkumar » Tue Apr 19, 2011 11:14 am in Coding Repository

8

17615

Mon May 20, 2013 2:46 am

gfsdfg View the latest post

No new posts Ecommerce website development and website Design

by iweballey » Fri May 17, 2013 7:15 am in PHP-Code Help

0

280

Fri May 17, 2013 7:15 am

iweballey View the latest post

No new posts How to upgrade and migrate Joomal site

by mallikharjuna rao » Mon Jan 21, 2013 1:40 pm in Joomla

1

356

Thu May 16, 2013 9:53 am

sunitha12 View the latest post

No new posts Benefits of PHP

by hirephpexpert » Fri Sep 07, 2012 4:41 am in CakePHP

6

1596

Wed May 15, 2013 6:25 am

PrettyPrincesG View the latest post


Your Ad Here