Jump to content

Help With RSS Feed Using PHP


SauloA

Recommended Posts

I'm trying to get the data in my database to display in my RSS Feed but there's supposedly an error in my code.  My web browser says it's the "mysql_fetch_array()" in my code where it says "while($row = mysql_fetch_array($result))" in the private function getDetails().  I found this code on the net and modified it to suit my needs.  Seems like I don't know what I'm doing though.  Can someone help me out?

 

Here's the full code I'm using:

 

This is the code that grabs the items for the RSS Feed:

<?php

class RSS
{
public function RSS()
{
	require_once ('Connections/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()
{
	$colname_rsShops = "1";
	if (isset($_GET['stateID'])) {
  		$colname_rsShops = $_GET['stateID'];
	}
	$detailsTable = "shop_tbl, state_lookup_tbl";
	$this->dbConnect($detailsTable);
	$query = "SELECT * FROM ". $detailsTable ."WHERE shop_state = ". $colname_rsShops ."AND shop_tbl.shop_approved = 1 AND shop_state = state_lookup_tbl.state ORDER BY shop_tbl.shop_name ASC";
	$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>Anime Shops In '. $row['full_state'] .'</title>
						<link>http://www.otakuwanted.com</link>
						<description>Find And Reveiw Anime Shops Near You At Otaku Wanted. Anime Shops In '. $row['full_state'] .'</description>
						<language></language>
						<image>
							<title></title>
							<url></url>
							<link></link>
							<width></width>
							<height></height>
						</image>';
	}
	return $details;
}

private function getItems()
{
	$colname_rsShops = "1";
	if (isset($_GET['stateID'])) {
  		$colname_rsShops = $_GET['stateID'];
	}
	$itemsTable = "shop_tbl, state_lookup_tbl";
	$this->dbConnect($itemsTable);
	$query = "SELECT * FROM ". $itemsTable ."WHERE shop_state = ". $colname_rsShops ."AND shop_tbl.shop_approved = 1 AND shop_state = state_lookup_tbl.state ORDER BY shop_tbl.shop_name ASC";
	$result = mysql_db_query (DB_NAME, $query, LINK);
	$items = '';
	while($row = mysql_fetch_array($result))
	{
		$items .= '<item>
					 <title>'. $row["shop_name"] .'</title>
					 <link>http://www.otakuwanted.com/shopselect.php?shopID='. $row["shop_id"] .'</link>
					 <description></description>
				 </item>';
	}
	$items .= '</channel>
			 </rss>';
	return $items;
}

}

?>

 

This is the code that's supposed to display all code above:

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

Link to comment
https://forums.phpfreaks.com/topic/88133-help-with-rss-feed-using-php/
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.