Jump to content

PHP to RSS not working :<


adamjones

Recommended Posts

Hi.

 

Ok, So I have this;

 

mysql_connect.php;

<?php

DEFINE ('DB_USER', 'name');
DEFINE ('DB_PASSWORD', 'pass');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'db');

$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );
mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() );

?>

 

Index.php:

 

<?php
header("Content-Type: application/xml; charset=ISO-8859-1");
include("classes/RSS.class.php");
$rss = new RSS();
echo $rss->GetFeed();
?>

 

RSS.class.php;

 

<?php

class RSS
{
public function RSS()
{
	require_once ('mysql_connect.php');
}

public function GetFeed()
{
	return $this->getDetails() . $this->getItems();
}

private function dbConnect()
{
	DEFINE ('LINK', mysql_connect (DB_HOST, DB_USER, DB_PASSWORD));
}

private function getDetails()
{
	$detailsTable = "webref_rss_details";
	$this->dbConnect($detailsTable);
	$query = "SELECT * FROM ". $detailsTable;
	$result = mysql_db_query (DB_NAME, $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>
						<language>'. $row['language'] .'</language>
						<image>
							<title>'. $row['image_title'] .'</title>
							<url>'. $row['image_url'] .'</url>
							<link>'. $row['image_link'] .'</link>
							<width>'. $row['image_width'] .'</width>
							<height>'. $row['image_height'] .'</height>
						</image>';
	}
	return $details;
}

private function getItems()
{
	$itemsTable = "webref_rss_items";
	$this->dbConnect($itemsTable);
	$query = "SELECT * FROM ". $itemsTable;
	$result = mysql_db_query (DB_NAME, $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;
}

}

?>

 

But it won't work. I get this error;

 

"error on line 1 at column 2: StartTag: invalid element name"

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/150517-php-to-rss-not-working/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.