Jump to content

Recommended Posts

I use RSS parser SimplePie in my site. SimplePie multifeeds code normally has something like this at the top:

$feeds = array(
'http://www.bloggerperson.com/feed.atom',
'http://www.yetanotherblog.com/?feed=rss2',
'http://feeds.feedburner.com/blogger',
);

 

I want to fill that list of RSS feeds from the database.

 

This script produces a nice list:

$query="SELECT rssfeed FROM users WHERE rssfeed!=''";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {

$rssfeed=mysql_result($result,$i,"rssfeed");

echo "'$rssfeed',<br />";

$i++;
}

 

The output looks something like this:

'http://www.bloggerperson.com/feed.atom',
'http://www.yetanotherblog.com/?feed=rss2',
'http://feeds.feedburner.com/blogger',

 

Exactly what I need. But how can I insert this output into the SimplePie script instead of echo-ing it on the page?

 

I suspect I need to put it into a function with return instead of echo. The SimplePie code would look something like this:

$feeds = array(
feedlist()
);

 

But I don't really have a clue how to do that. I've tried all kinds of variations without luck. Am I on the right track? Is it possible to use results from one part of the script as input for other parts? How?

Thanks duclet. Tried it. I get a syntax error:

 

Parse error: syntax error, unexpected '{' in ... on line 14

 

That's the first { in your suggestion. Simply removing it doesn't solve the problem.

 

Is an array really the same as that list with '...',? I've tried other similar suggestions. None worked. Some produced an "unreadable" error from the SimplePie script.

 

That's why I'm looking for a solution that literally inserts that echo output into SimplePie. At least I know in theory that should work. I'm less sure about the more sophisticated array solutions.

 

Edit: Another source just gave me this solution:

 

$rss_feeds = array();
while ($data = mysql_fetch_assoc($result))
{
    $rss_feeds[] = $data['rssfeed'];
}

// Initialize some feeds for use.
$feed = new SimplePie();
$feed->set_feed_url($rss_feeds);

 

It's basically the same, but solves the syntax error. However it shows post(s) from only one of the available RSS feeds. That's why I'm trying to find out if the "insert echo output elsewhere in the script" is possible.

 

That's my question. Just ignore the specific problem I'm trying to solve. All I'm trying to find out is how to insert output from one part of a script into another part, instead of echo-ing it on the page. Is it at all possible? Do I need a function?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.