Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RSS/Magpie - multiple feeds 2

Status
Not open for further replies.

Hondy

Technical User
Mar 3, 2003
864
GB
Sorry if this is in the wrong forum, can anyone help?

When doing more than one feed using Magpie, I get:
Cannot redeclare fetch_rss() (previously declared)

This is obviously because the line
include('rss/rss_fetch.inc');$rss = fetch_rss(' can only be used once. I'm not a programmer so can anyone tell me how to put up more feeds from different URLS? (I can get one feed per page easy enough)

Much appreciated, thanks.
 
Hmmm... Well, it's hard to see what's going on without seeing more of the code, but here's what I think.

You've actually got two commands there:
Code:
include('rss/rss_fetch.inc');
This bit includes the contents of another file into your program. Presumably that file has the definition of the [tt]fetch_rss()[/tt] function. This command should only appear once in your program!

The other half
Code:
$rss = fetch_rss('[URL unfurl="true"]http://URLHERE.rss')[/URL]
says "use the fetch_rss function to get a feed from this URL, and put the results into a variable called $rss". Presumably, further down the program, you do things with
[tt]$rss[/tt] like print it or parse it for its content or whatever. You should be able to make multiple calls to [tt]fetch_rss[/tt], either reading each feed into its own variable...
Code:
$rss1 = fetch_rss('[URL unfurl="true"]http://FIRSTURL.rss')[/URL]
$rss2 = fetch_rss('[URL unfurl="true"]http://SECONDURL.rss')[/URL]
$rss3 = fetch_rss('[URL unfurl="true"]http://THIRDURL.rss')[/URL]
and doing stuff with each one, or by re-using the $rss variable when you've finished with it...
Code:
$rss = fetch_rss('[URL unfurl="true"]http://FIRSTURL.rss')[/URL]
  ... do stuff with first feed ...
$rss = fetch_rss('[URL unfurl="true"]http://SECONDURL.rss')[/URL]
  ... do stuff with second feed ...
$rss = fetch_rss('[URL unfurl="true"]http://THIRDURL.rss')[/URL]
  ... do stuff with third feed ...

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
PS. Googling came up some PHP which seems to be calling this function. They include the code like this:
Code:
require_once('rss/rss_fetch.inc');
I don't speak PHP, but it looks like that's a built-in way of protecting yourself from including the same file twice.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Thanks for the response Chris. Your assumptions are correct, the thing is I guessed your both of suggestions and they both output the error above... any other ideas?
 
You have more than one instance of the include statement on your page.

Or you are calling the file that contains the include more than once.

You only need include the magpie file once, then your script can use it as many times as it likes.

Foamcow Heavy Industries - Web design and ranting
Toccoa Games - Day of Defeat gaming community
Target Marketing Communications - Advertising, Direct Marketing and Public Relations
"I'm making time
 
I see what you are saying Chris, thanks, I'll probably need to adapt it using the require_once, I'm 'learning' PHP as I go.

Foamcow I just realised what you mean in the middle of responding, and resolved it...it really was as simple as taking out the include statement on the second PHP script! Easy when you can do it! :D

On a separate note, you wouldn't know how to remove the bullet point that Magpie seems to put in for you to distinguish each article would you?
 
right, li = list items = bulleting, got ya - thanks for your help, I guess I should do HTML basics before I do PHP and RSS :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top