Build Your Own RSS Feed with PHP and mySQL

Here’s a quick tutorial to build a RSS Feed based on your own database. Just replace the details and modify the SQL command. (I)

First we have to declare the header.. Remember, the header MUST be written in the first line of the script. this is why.

<?
header ("content-type: text/xml");

and then your database details

// Database config
$dbhost="localhost";
$dbname="your_db";
$dbuser="root";
$dbpass="rootpassword";
$koneksi = mysql_connect ($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname);
// database end

this is a must element of your RSS, just write it..

 $today = date("D, j M Y G:i:s");
 echo '<?xml version="1.0" encoding="UTF-8"?>';
 ?><rss version="2.0"
 xmlns:content="http://purl.org/rss/1.0/modules/content/"
 xmlns:dc="http://purl.org/dc/elements/1.1/"
 xmlns:atom="http://www.w3.org/2005/Atom"
 xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
 >
 </rss>

you can tweak the details inside the element bellow:

<channel>
 <title>Android Repo Browser</title>
 <atom:link href="http://andiim3.com/feed" rel="self" type="application/rss+xml" />
 <link>http://andiim3.com</link>
 <description>Latest android AKP for download</description>
 <lastbuilddate>< ?=$today?> +0000</lastbuilddate>
 <sy:updateperiod>hourly</sy:updateperiod>
 <sy:updatefrequency>1</sy:updatefrequency>
 <generator>http://andiim3.com/feed</generator>
 </channel>

now we fetch your data from the database. Modify the SQL command based on your own database structure.

<?
 $sql=mysql_query("select * from apks order by `date` DESC LIMIT 20");
 while($data=mysql_fetch_array($sql)){
 $size=$data[size];
 if($size<=1024){$size=round($size, 2);$sizes="$size byte";}
 if($size>=1024){$size=$size/1024;$size=round($size, 2);$sizes="$size KB";} // KB
 if($size>=1024){$size=$size/1024;$size=round($size, 2);$sizes="$size MB";} // MB
 $date=$data[date];
 list($Y, $m, $d)=explode("-",$date);
$today = date("D, j M Y G:i:s", mktime(0, 0, 0, $m, $d, $Y)); //date("D, j M Y G:i:s");
 echo "<item>
 <title> $data[name]</title>
 <link>http://andiim3.com/?apk=$data[apkid]</link>
 <dc:creator>andiim3</dc:creator>
 <pubdate>$today +0000</pubdate>
 <guid isPermaLink=\"true\">http://andiim3.com/?apk=$data[apkid]</guid>
 <description>$data[name] (Ver: $data[ver]) - APK ID: $data[apkid] - Size : $sizes - Date added: $data[date]</description>
 <content:encoded>< ![CDATA[ <img src=\"$data[icon]\" />$data[name] (Ver: $data[ver]) - APK ID: $data[apkid] - Size: $sizes - Date added: $data[date]
 ]]></content:encoded>
 </item>
 ";}
 ?>

now close the feed

</channel>
 </rss>

See my feed here: andiim3.com/feed , and see the source (right click, view source)

Andi Setiawan

Loving husband - Caring Father - Slap bet Commissionaire (I wish) find my complete profile on: http://andisetiawan.com/about-me http://facebook.com/andiim3 - http://gplus.to/andiim3 - http://andiim3.com

Share
Published by
Andi Setiawan

Recent Posts

Dedicated Blog for Dobby and Luna

Dobby and Luna have been part of our lives for the past years. They have…

2 years ago

Demo Site For My Projects

In the year 2021, I've completed some paid projects. Some of them are more technical,…

2 years ago

GlassTime – Glassmorphism WordPress Theme

Based on the GlassTime Bootstrap template, here I present glassmorphism WordPress Theme free to download.This…

3 years ago

GlassTime : Glassmorphism Responsive HTML5 Template

This HTML5 template is using Glassmorphism UI design language which is now trending for 2021…

3 years ago

Daftar Desa, Kecamatan, dan Kode Pos Buleleng – Bali

KecamatanKode POSBanjar81152Buleleng81119Busungbiu81154Gerokgak81155Kubutambahan81172Sawan81171Seririt81153Sukasada81161Tejakula81173Klik pada nama kecamatan untuk melihat daftar desa masing-masing. Sumber: kodepos.andiim3.com

3 years ago

Ninja diganti ADV

Ada yang bilang "semuanya akan mati matic pada akhirnya". Bener aja, sekarang tuntutan transportasi sehari-hari…

4 years ago

This website uses cookies.