Page 1 of 1
RSS feed php + mysql
Posted: Sun Feb 28, 2010 9:32 am
by aravona
I've been following a tutorial on RSS feeds which utilises php and mysql. It creates a function and there doesnt seem to be any problems with it, at least I'm getting no warnings, notices or fatal errors.
Whats happening though is the following bit of code which is supposed to put the feed on the page is instead just echoing the function name:
Code: Select all
<?
header("Content-Type: application/xml; charset=ISO-8859-1");
include("classes/RSSclass.php");
$rss = new RSS();
echo $rss->GetFeed();
?>
this ends up putting this on the screen
Since its a tutorial and this is the first time I've built my own RSS feed I'm a little stumped.
Re: RSS feed php + mysql
Posted: Sun Feb 28, 2010 10:12 am
by davex
Try viewing the source of the page - I think you'll find the source code maybe has some extra data - looks like maybe the opening < is being shown until the > found at the -> class pointer and so the whole lot is being taken as an HTML element.
Also I would try changing the initial line from <? to <?php.
Cheers,
Dave.
Re: RSS feed php + mysql
Posted: Sun Feb 28, 2010 12:12 pm
by aravona
Thanks switching all that around got rid of the problem but now my screen shows:
Code: Select all
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------
System error: -2146697204. Error processing resource 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'.
Only I'm not sure what the problem can be, I'm new to RSS feeds like I said.
Code: Select all
<?php
class RSS
{
public function RSS()
{
require_once ('connection.php');
}
public function GetFeed()
{
return $this->getDetails() . $this->getItems();
}
private function dbConnect()
{
DEFINE ('LINK', mysql_connect (localhost, 'Aravona', 'texass9'));
}
private function getDetails()
{
$detailsTable = "rss_details";
$this->dbConnect($detailsTable);
$query = "SELECT * FROM ". $detailsTable;
$result = mysql_db_query (gametest, $query, LINK);
while($row = mysql_fetch_array($result))
{
$details = '<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">
<channel>
<title>'. $row['title'] .'</title>
<link>'. $row['link'] .'</link>
<description>'. $row['description'] .'</description>';
}
return $details;
}
private function getItems()
{
$itemsTable = "rss_items";
$this->dbConnect($itemsTable);
$query = "SELECT * FROM ". $itemsTable;
$result = mysql_db_query (gametest, $query, LINK);
$items = '';
while($row = mysql_fetch_array($result))
{
$items .= '<item>
<title>'. $row["title"] .'</title>
<link>'. $row["link"] .'</link>
<description><![CDATA['. $row["description"] .']]></description>
</item>';
}
$items .= '</channel>
</rss>';
return $items;
}
}
?>
Though I dunno what to do now?
Re: RSS feed php + mysql
Posted: Sun Feb 28, 2010 12:34 pm
by davex
Hi,
Ok there are a few things with your script - for example it looks like you're outputting the XML header within the while loop.
What browser are you using? (The error is unfamiliar to me).
Anyway - view the source of the page and post the XML that has been output please unless of course the problem is obvious.
Only some browsers will support direct display of XML data correctly including RSS. Firefox does it fine as long as all the schema is correct.
Cheers,
Dave.
Re: RSS feed php + mysql
Posted: Sun Feb 28, 2010 1:19 pm
by aravona
I cannot view the souce code if I try it says 'The XML source file is unavailable for viewing' So I guess soemthing is really messed up but I've only worked with plain XML pulled with javascript once or twice.
Like I said this is from a tutorial and there were no complaints with it not working.
Re: RSS feed php + mysql
Posted: Sun Feb 28, 2010 1:25 pm
by davex
What browser are you using?
So you're pulling the XML data via JavaScript. I think you said it works ok if you view the page directly in the browser rather than pulling it via JavaScript? Can you view the source then?
Cheers,
Dave.
Re: RSS feed php + mysql
Posted: Sun Feb 28, 2010 1:55 pm
by davex
Hi - try this to see the source output.
Change your index page to the following:
Code: Select all
<?
//header("Content-Type: application/xml; charset=ISO-8859-1"); // commenting out this line
include("classes/RSSclass.php");
$rss = new RSS();
echo htmlspecialchars($rss->GetFeed()); // wrapping $rss->GetFeed() in htmlspecialchars()
?>
It should output the XML as HTML and you can see it on the browser page.
Cheers,
Dave.
Re: RSS feed php + mysql
Posted: Mon Mar 01, 2010 1:21 am
by aravona
I'm afraid that didnt work, I may have to try something else out. I do have some access to other RSS feeds so will have to give it another try when I can acces them.
Thanks for helping though
