Page 1 of 1

XML and PHP

Posted: Sat Nov 22, 2003 12:17 pm
by Nay
Hey, I was getting into the whole XML and PHP thing and I saw this newsfeed on Jason's site and started getting into it. Well, so far I've got this script. It's working fine but I'd like some opinions from the experianced. So anyway:

Code: Select all

<?php

require "templates/config.php";
$config = new config();
$host = $config->mysql_host;
$user = $config->mysql_user;
$pass = $config->mysql_pass;
$data = $config->mysql_data;

$connection = mysql_connect($host, $user, $pass);
$database = mysql_select_db($data, $connection);
$id = $_GET['id'];

header ("Content-type: text/xml");

if(isSet($id) && !empty($id) && is_numeric($id)) {

// feed for a selected article <-- not completed yet

} else {

echo <<< XML
<?xml version="1.0" encoding="ISO-8859-1"?>

<rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:hr="http://www.w3.org/2000/08/w3c-synd/#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/">

   <channel>
       <title>ChaosDreamers.com News and Updates</title>
       <description>ChaosDreamers.com - Blog, News, Articles, RSS/RDF Feed</description>
       <link>http://www.chaosdreamers.com</link>
   </channel>

   <channel>
XML;

$query2 = "select *, date_format(date, '%d-%m-%y') as for_date from news order by id desc limit 10";
$result2 = mysql_query($query2, $connection) or die(mysql_error());

   while($rows=mysql_fetch_array($result2)) {
   $news = str_replace("\n", "<br />", $rows['news']);
echo <<< ITEM

   <item>
      <title>{$rows['title']}</title>
      <date>{$rows['for_date']}</date>
      <news>$news</news>
   </item>
ITEM;

   }

echo <<< END

   </channel>

</rdf:RDF>
END;

}
?>
Thanks,

-Nay

Posted: Sat Nov 22, 2003 2:18 pm
by Gen-ik
oppps.... sorry.... just passing through....