modifiedcontent Posted January 2, 2008 Share Posted January 2, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/84039-insert-echo-output-elsewhere-in-the-script/ Share on other sites More sharing options...
duclet Posted January 2, 2008 Share Posted January 2, 2008 Try this: $query = "SELECT rssfeed FROM users WHERE rssfeed != ''"; $result = mysql_query($query); $feeds = array(); while($row = mysql_fetch_assoc($result) { $feeds[] = $row['rssfeed']; } Now $feeds become that array you need. Quote Link to comment https://forums.phpfreaks.com/topic/84039-insert-echo-output-elsewhere-in-the-script/#findComment-427733 Share on other sites More sharing options...
modifiedcontent Posted January 2, 2008 Author Share Posted January 2, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/84039-insert-echo-output-elsewhere-in-the-script/#findComment-427751 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.