Ad block is installed and active. Please support us by disabling it.
HomeThursday, September 21, 2017, 03:23:22
1

MySQL to RSS

Tuesday, February 10, 15, 00:36:07, 3 Yaers Ago Via wain, Hits: 2607
Publishing MySQL data in RSS
config.php

Code:
<?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 (mysql_error());
endif;
?>


rss.php

Code:
<?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>
<title>example.com</title>
<description>news example.com</description>
<link>http://example.com</link>
<?php
include ('config.php');
$res = mysql_query("SELECT id, title, description, date
FROM news ORDER by date DESC LIMIT 5")
or die(mysql_error());
while($row = mysql_fetch_array($res)){
?>
<item>
<title> <?php echo $row['title']; ?></title>
<description> <?php echo htmlspecialchars($row['description'], ENT_QUOTES); ?> </description>
<link>http://example.com/?id=<?php echo $row['id']; ?></link>
<guid>http://example.com/<?php echo $row['id']; ?>.html</guid>
<pubDate> <?php echo date("r", strtotime($row["date"])); ?></pubDate>
</item>
<?php
}
?>

Sign In

Sponsor

Related

Show / Hide Div with CSS

CSS Display and Visibility:The visibility property specifies whether or not an element is visible.

PHP Date Examples

Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given.

Images In Textarea - CSS

Tutorial Images in Textarea

Inserting form data in MySql table

Inserting form data in MySql table with PHP

Upload Image with PHP [Example2]

[Example2] Tutorial - How to upload and resize image with PHP

Contact Us Form With Captcha

A contact us form with email and form field validation. It allows your visitors to send you an email directly from your website. Features: Captcha Image, HTML output.

Comments 1.1. :: PHP Script

This script allows your visitors to add comments to any single page on your web site.

PHP Redirect

Header (location) redirect must be processed before any output to the browser.

PHP imagecreate

imagecreate() returns an image identifier representing a blank image of specified size.

Meta Tags Generator 1.1. PHP Script

This script will allow your visitors to create meta tags online.
About Author

wain

Date Registered: Sun, Feb 8, 15
Last Time Online: Thu, Jun 15, 17
So far has created 115 entries.
wain
This author has not yet filled in any details.