Build Your Own RSS Feed with PHP and mySQL | andi setiawan's blog

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
$koneksi = mysql_connect ($dbhost, $dbuser, $dbpass);
// 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"

you can tweak the details inside the element bellow:

 <title>Android Repo Browser</title>
 <atom:link href="" rel="self" type="application/rss+xml" />
 <description>Latest android AKP for download</description>
 <lastbuilddate>< ?=$today?> +0000</lastbuilddate>

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");
 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
 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>
 <pubdate>$today +0000</pubdate>
 <guid isPermaLink=\"true\">$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]

now close the feed


See my feed here: , and see the source (right click, view source)

Posted in programming, Tips n Trik, Tutorial |

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: