This is an example of generating an xml output format from the database.
This code is creating a sample rss feed from the joomla articles (which can be added to a rss.xml file).
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "joomla";
mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);
mysql_query("SET NAMES 'utf8'"); // to get proper format
$sql = "SELECT id, title, alias, title_alias, metadesc FROM `jos_content`
where catid=12 limit 3";
$q = mysql_query($sql) or die(mysql_error());
$xml = "";
while($r = mysql_fetch_array($q)){
$xml .= "<item>";
$xml .= "<title>".trim($r['title'])."</title>";
$xml .= "<link>".trim($r['title_alias'])."</link>";
$xml .= "<pubDate>Fri, 06 Jan 2012 08:30:00 GMT</pubDate>";
$xml .= "<description>".trim($r['metadesc'])."</description>";
$xml .= "</item>";
}
header("content-type: application/xml;");
echo $xml;
?>
Note: Run the file. If you dont see the xml output, try to view the source code...
This code is creating a sample rss feed from the joomla articles (which can be added to a rss.xml file).
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "joomla";
mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);
mysql_query("SET NAMES 'utf8'"); // to get proper format
$sql = "SELECT id, title, alias, title_alias, metadesc FROM `jos_content`
where catid=12 limit 3";
$q = mysql_query($sql) or die(mysql_error());
$xml = "";
while($r = mysql_fetch_array($q)){
$xml .= "<item>";
$xml .= "<title>".trim($r['title'])."</title>";
$xml .= "<link>".trim($r['title_alias'])."</link>";
$xml .= "<pubDate>Fri, 06 Jan 2012 08:30:00 GMT</pubDate>";
$xml .= "<description>".trim($r['metadesc'])."</description>";
$xml .= "</item>";
}
header("content-type: application/xml;");
echo $xml;
?>
Note: Run the file. If you dont see the xml output, try to view the source code...
Comments
Post a Comment